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 trialRifqi Fahmi
23,164 Pointslearning to use and handle many image resources in android !
I wonder is there a lesson to teach student how to handle bitmap on android especially large bitmap. Why i ask this ? because I follow this lesson https://teamtreehouse.com/library/build-a-simple-android-app-2014 and I want to have some images that represent each fact. It still work fine for 3-4 facts, but when I try to compile more than 4 facts and run the app it give an exception "OutOfMemory Exception" because the app try to load all the image at once.
It would be nice if teamtreehouse add some lesson for this kind of topic. So that we can make such as our own gallery app hehe :) Ben Jakuben Ben Deitch
Thanks :D
1 Answer
Ben Deitch
Treehouse TeacherTry putting the images in the /res/drawable-nodpi directory (you may need to create it). It's not well documented, but I think I've used it in the past as a quick fix for this issue.
Rifqi Fahmi
23,164 PointsRifqi Fahmi
23,164 Pointshmmmm I think this is the best way https://developer.android.com/training/displaying-bitmaps/index.html what do u think?
Ben Deitch
Treehouse TeacherBen Deitch
Treehouse TeacherI think that way's a lot more work ;).
If a drawable is in the nodpi folder, then Android will scale it to fit the device which MAY cause the image to become a little blurry/pixelated. But on the other hand, dealing with 5 different drawable folders and OutOfMemory Exceptions is a TON of extra work. So it's really up to you. Are you trying to have the best image quality possible, or would you rather do a lot less work with nodpi?
Rifqi Fahmi
23,164 PointsRifqi Fahmi
23,164 Pointshaha i am just curious with this bitmap things, i think handling the bitmap resource is important so we can get nice user experience. nodpi also work, But nodpi is kind of simple and it still load the image at once, imagine if i have tons of fact and user have to wait for the system to load at a time, it will took their precious time hehe.
Thanks for answering :D