【问题标题】:Bitmap in notification remoteviews cannot recycle通知远程视图中的位图无法回收
【发布时间】: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


【解决方案1】:

重新为您的应用程序使用相同的远程视图将导致内存不足错误。 因此,与其回收,不如重新创建远程视图。 https://groups.google.com/forum/m/#!topic/android-developers/qQ4SV5wL7uM

【讨论】:

  • 是的,你是对的......我曾经重复使用remoteview
猜你喜欢
  • 2018-03-07
  • 1970-01-01
  • 2015-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-03
相关资源
最近更新 更多