Bitmap in remote view notifications cannot be recycled

I want to write an application for mp3 players. show music album on notification

Here is the code:

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

      

but this leads to running out of memory after I change a lot of music. So I am recycling mCoverBitmap. But he crashed. java.lang.IllegalStateException: Unable to process rendered bitmap

Then I try to cache the bitmap. And rework it the next time we need a notification.

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

      

But this leads to the same exception. how to rework bitmap?

+3


source to share


1 answer


Reusing the same remote view for your application will result in an out of memory error. So instead of recycling, just re-create the remote views. https://groups.google.com/forum/m/#!topic/android-developers/qQ4SV5wL7uM



0


source







All Articles