fresco icon indicating copy to clipboard operation
fresco copied to clipboard

Using Fresco together with a Notification

Open bottiger opened this issue 11 years ago • 4 comments

Could you please help with some documentation of how to use Fresco together a Notification (or any other RemoteView). You have documented how to fetch a CloseableImage from the cache, but It is not clear to me when (in the context of a notification) when to close the image again in this case.

bottiger avatar Apr 25 '15 19:04 bottiger

I have the same question, especially when I need to use bigPicture on my notification style.

brubraz avatar Apr 25 '15 20:04 brubraz

The easiest way for a Notification is to use BaseBitmapDataSubscriber. Inside the onNewResultImpl method, you can call [NotificationCompat.Builder.setLargeIcon][http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setLargeIcon(android.graphics.Bitmap)). Then you don't have to worry about closing the bitmap.

tyronen avatar Apr 26 '15 09:04 tyronen

@tyronen Thank you for this. I have not tested it yet, and while I'm happy I'm also a bit confused. The documentation says

You can not assign the bitmap to any variable not in the scope of the onNewResultImpl method. The reason is that, after the subscriber has finished executing, the image pipeline will recycle the bitmap and free its memory. If you try to draw the bitmap after that, your app will crash with an IllegalStateException.

I am not aware of the internal workings of the Android UI. However, I interpreted this as assigning a bitmap to a (remote) view means that the bitmap is kept alive and used beyond the scope of "onNewResultImpl".

bottiger avatar Apr 27 '15 07:04 bottiger

No. Internally, Android copies the Bitmap in order to send the data over to the notification or remote view process. So you don't need to keep a reference to it after you have copied it. I can add this to the docs.

tyronen avatar Apr 27 '15 09:04 tyronen