安卓loadIcon产生的OutOfMemoryError [英] android loadIcon generates outOfMemoryError

查看:664
本文介绍了安卓loadIcon产生的OutOfMemoryError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是有一点点的ListView 包含所有安装的应用程序及其图标
但是,如果没有安装太多应用程序我碰到<​​code> OutOfMemoryError异常而做

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()));

对于每个一个ListEntry (这条线是写在我的 ListAdapter

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

没问题的,到目前为止,我明白了为什么我遇到了这个错误(太多的图标加载,过少的VM堆)
但我看了一下机器人的源$ C ​​$ C ManageApplications 活动的设置
我从来没有在任何这些运行的 OOM错误在使用设置 ManageApps
但奇怪的是,他们这样做的完全相同的方式

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

,你可以在这里它们的来源看:
<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android-apps/4.3_r1/com/android/settings/applications/ManageApplications.java"相对=nofollow>的 ManageApplications 活动
<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android-apps/4.3_r1/com/android/settings/applications/ApplicationsState.java#ApplicationsState.ensureIcon%28com.android.settings.applications.ApplicationsState.AppEntry%29"相对=nofollow>其中的可绘制图标被加载
<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android-apps/4.3_r1/com/android/settings/applications/ManageApplications.java#ManageApplications.ApplicationsAdapter.getView%28int,android.view.View,android.view.ViewGroup%29"相对=nofollow>当在列表视图设置

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

但我真的不明白为什么我得到一个OOM,他们不?

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

推荐答案

解决它自己。
我现在每加载图像到缓存中使用它之前。
如果缓存已满,最旧的元素将被丢弃,
因此新的可获取缓存。 此外即时调整我的图片为较小的图标。
该做的。

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.

这篇关于安卓loadIcon产生的OutOfMemoryError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆