Search code examples
androidservicenotificationsandroid-notificationsforegroundnotification

Android Updating notification text causes memory usage


So I have a service with a foreground notification that is launched when the user navigates away from the activity.

I update this notification consistently every second with a String that has a time, but every update causes the memory usage to go up by at least 0.01 MB. Here's the code I'm using:

mNotiBuilder.setContentText(mBuilder.toString());
mNotiManager.notify(notificationId, mNotiBuilder.build());

I've tested that the string builder I'm using is not causing it.

I don't really know why this is happening, should I be even worried about it at all? I'm a stickler when it comes to resource usage so I'm trying to get this right.


Solution

  • Well I wouldn't worry too much. Each time you build a new Notification, it will take some memory. Android probably doesn't run a garbage collection cycle as long as you have enough memory, meaning that old Notification will stay around for a while.