TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Android Image Problems

4 pointsby campnicabout 13 years ago

1 comment

aguynamedrichabout 13 years ago
The OutOfMemory issue is a pretty big problem, but I'd say it's quite lazy to just dismiss it as something the framework needs to fix so that you can effectively do your job. I ran into this problem a lot early on in my Android development, and as I studied it further I found tons of resources and information to make it work in all cases and there are plenty of creative solutions documented in blogs and discussed on StackOverflow about it as well. Half the time you can get around this error by recycling your bitmaps when you're done with them and/or rethinking your approach to needing really large bitmaps in memory at the same time. There are two things I've done commonly in apps to get around this.<p>(1) If I'm just expanding included resource files (compressed images) into bitmaps for display, I write my own intelligent cache. Backed by a simple HashMap, I can even include in my cache keys the desired height and width and downsample intelligently and cache the downsampled version. Funny enough, when I presented this to my coworker, he had just done almost the exact same thing and we had never discussed it. In one case I needed to categorize my images to flush some and not others from the cache, so I just wrapped a bunch of instances of the same BitmapCache into a BitmapCacheManager class and it worked like a charm.<p>(2) To get around the fact that you can't just set the source path of an ImageView to a web url, you can use a custom class that wraps ImageView and just handles downloading the image on a background thread. I wrote a pretty complicated system that pumps the urls to a queue and broadcasts a notification when each download completes, but a single google search pointed me to an awesome apache licensed library that does exactly the same thing (and is admittedly cleaner than mine).<p><a href="https://github.com/loopj/android-smart-image-view" rel="nofollow">https://github.com/loopj/android-smart-image-view</a><p>It's totally doable. I never looked at it as a limitation of the framework - I actually saw it as an opportunity to do something more challenging than just drawing within the lines of the framework.
评论 #3861424 未加载