android loadIcon generates outOfMemoryError

2019-02-20 15:16发布

I just have a little ListView containing all installed apps and their icons
but if there are too much Apps installed i run into outOfMemoryErrors while doing

Drawable app_icon = applicationInfoList.get(i).loadIcon(context.getPackageManager()));

that for every ListEntry (this line is written in my ListAdapter)

no problem so far, i understand why i ran into this error (too much icons loaded, too few vm heap)
but i had a look at the source code of androids ManageApplications Activity in the settings
and i never run in any of those oom errors while using the settings ManageApps
but the weird thing is that they do it EXACTLY THE SAME WAY

as you can see in their source here:
the ManageApplications activity
where the Drawable icon gets loaded
where it is set in the list view

but i really dont understand why do i get a oom and they dont?

2条回答
看我几分像从前
2楼-- · 2019-02-20 16:08

Solved it myself.
I'm now loading every image into a cache before using it.
If the cache gets full, the oldest element will be discarded,
so new ones can get cached. additionally im resizing my images into smaller icons.
that did it.

查看更多
在下西门庆
3楼-- · 2019-02-20 16:13

Resize your icons into small images, you will be fine! (had this problem before, too)

查看更多
登录 后发表回答