通知 RemoteViews 中的位图无法回收利用。

3

我希望编写一个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
1
@Blackbelt 位图非常小,多个位图不会导致内存溢出。 - Shaw
1个回答

1

是的,你说得对...我曾经重复使用RemoteView。 - Shaw

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接