Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Emeka Farrier
Courses Plus Student 2,892 PointsBuilding simple image gallery
I'm building a simple image gallery. There's 3 buttons previous, next and random. These buttons does exactly what it suggests.
When clicked I'm setting the imageResource via setImageResource(id). This however when a button is clicked excessively the application runs out of memory thus force closing the app. What efficient approach i can take to implement this simple image gallery concept without running into that error? Thanks in advance
2 Answers
Luca Dan
6,012 PointsHi, Try to use AsyncTask. AsyncTask class allows us to perform long lasting tasks/background operations and show the result on the UI thread without affecting the main thread. Dan
Luca Dan
6,012 PointsYes, you can
Emeka Farrier
Courses Plus Student 2,892 PointsHadn't posted as best answer because I haven't tried it. Finally did and it works fine thanks ^.^
Emeka Farrier
Courses Plus Student 2,892 PointsEmeka Farrier
Courses Plus Student 2,892 PointsCan async task be used even though I'm not loading in data from the web?