2

I am creating notification with music controls. Everything is fine except artwork update.

The original artwork Bitmap is like 1024x1024 pixels or around so. If I call setImageBitmap(, ) for my RemoteViews directly, it causes lags. If I'm trying to create new, smaller Bitmap via Bitmap#create(), then there is still lag.

So, what am I doing wrong?

2 Answers2

3

Brett is right. However, it looks more like a bug than a feature.

Instead of re-using the same RemoteViews with different bitmap, I re-create RemoteViews every time with new Bitmap and then send it to a Notification. Strangely, this doesn't cause much lag.

  • Dude your answer helped me solve a big problem today. I posted this q http://stackoverflow.com/questions/39103189/android-notification-stops-updating-once-it-has-updated-for-a-certain-number-of more than 20 days back. And I got no answers even though I put a bounty. Thanks to your observation I finally solved it. These strange bugs in android can really make you suffer. – varunkr Sep 13 '16 at 20:32
1

I have run into this as well. SetImageBitmap is expensive as it must marshal the bitmap across the IPC boundary. This requires a large alloc in order to store the bitmap in the IPC message, then there's the actual marshaling of a large blob of memory. You will almost always see a GC_FOR_ALLOC message every time you use setImageViewBitmap. And that is a preemptive GC (world-stopping) which is probably where your lag is coming from.

Ideally, you should use setImageViewUri with a file:// Uri, this alleviates the above IPC concerns and is reasonably fast.

So, bottom line, is that if you are setting bitmaps of any significant size (i.e. larger than a small icon), you will see this lag.

Brett Duncavage
  • 2,163
  • 14
  • 16