Majid Aljishi
Majid Aljishi

Reputation: 57

Why is notification manager (notify) method is so expensive for memory when loop?

while (key){
    builder.setNumber(++numMessages);
    manager.notify(notifyID, builder.build());
}

Upvotes: 0

Views: 99

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199805

Notifications involve sending all of the data, including every Bitmap, from your application to the Android system. Prior to Android 7.0, this caused the data to be entirely copied before being sent over.

Of course, media players should be using MediaStyle notifications which are specifically designed for things like playback controls. They do not show the current playing time.

However, if you really need to show the current time, you should instead use setUsesChronometer(true) which changes the time set with setWhen into the start of a timer which will automatically update every second without you having to call notify every second.

Upvotes: 3

Related Questions