回收位图冰淇淋三明治强制关闭
在我的 ondestroy 方法中,我回收了用于释放内存并防止应用程序在屏幕旋转期间崩溃的所有位图。事实证明,这对所有 api 来说都是正确的做法,直到冰淇淋三明治(android 4.0)为止。现在,当我在 ICS 上轮换时,我会强制关闭并且 logcat 没有用。我无法追溯到我的代码,但是当我删除位图回收时,它对 ICS 非常有用。对此有什么想法吗?
In my ondestroy method, I recycle all the bitmaps I've used to free up memory and keep the app from crashing during screen rotations. This has proven to be the right thing to do for all apis until ice cream sandwich (android 4.0). now, when I rotate on ICS I get a force close and the logcat is not useful. I cannot trace it back to my code, but when I remove the bitmap recycling, it works great for ICS. Any ideas on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否回收从资源中检索到的位图?听起来操作系统保留了对位图的引用,并将其用于将来对同一资源的调用。在这种情况下,当屏幕旋转时,它将尝试使用您刚刚回收的相同位图。这将导致强制关闭。
您可能根本不需要手动回收位图。这是一个非常危险的调用,尤其是在从资源加载的位图上。
Are you recycling bitmaps that were retrieved from the resources? It sounds like the OS keeps a reference to the Bitmap and uses it for future calls to the same resource. In that case, when the screen rotates, it will try to use the same Bitmap that you just recycled. This will result in a force close.
You may not need to recycle the bitmaps manually at all. It is a very dangerous call, especially on Bitmaps loaded from the resources.