I want to write mp3 player app. 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 it leads to out of memory after I change a lot of music. So I recycle the mCoverBitmap. But it crashed. java.lang.IllegalStateException: Can't parcel a recycled bitmap
Then I try to cache the bitmap. And recycle 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 it leads to the same exception. how to recycle the bitmap?