【发布时间】:2015-04-21 09:57:29
【问题描述】:
我想编写 mp3 播放器应用程序。在通知中显示音乐专辑
代码如下:
mCoverBitmap = MusicModel.getAlbumArt(musicItem.getUri());
if (mCoverBitmap != null) {
mNormalRemoteViews.setImageViewBitmap(R.id.notification_image, mCoverBitmap);
} else {
mNormalRemoteViews.setImageViewResource(R.id.notification_image, R.drawable.default_album);
}
但是我换了很多音乐后会导致内存不足。所以我回收了mCoverBitmap。但它崩溃了。 java.lang.IllegalStateException:无法打包回收的位图
然后我尝试缓存位图。并在我们下次需要通知时回收它。
BitmapUtil.recycleBitmap(mCoverCache);
mCoverCache = mCoverBitmap;
mCoverBitmap = MusicModel.getAlbumArt(musicItem.getUri());
if (mCoverBitmap != null) {
mNormalRemoteViews.setImageViewBitmap(R.id.notification_image, mCoverBitmap);
} else {
mNormalRemoteViews.setImageViewResource(R.id.notification_image, R.drawable.default_album);
}
但它会导致同样的异常。 如何回收位图?
【问题讨论】:
-
位图有多大?
-
@Blackbelt 位图很小,多张位图不会导致oom
标签: java android bitmap remoteview