Update text of notification, not entire notification

Be sure to use the same NotificationCompat.Builder builder each time for creating the Notification!

Although the first time you have to set everything, the second time using the Builder you only have to set the value(s) you want to update. After that it’s calling notificationManager.notify(id, builder.build()) just like you did. If you use the same ID then the notification gets updated (important!).


//First time
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                    PendingIntent.getActivity(context, 10, 
                            new Intent(context, FrontActivity.class)                                 
            .addAction(running ? R.drawable.ic_action_pause 
                               : R.drawable.ic_action_play,
                       running ? context.getString(R.string.pause)
                               : context.getString(R.string.start),
            .addAction(R.drawable.ic_action_stop, context.getString(R.string.stop),

notificationManager.notify(id, builder.build());

//Second time
notificationManager.notify(id, builder.build());

But you can also use the setUsesChronometer method of the NotificationCompat class. This automatically displays a chronometer using the given timestamp (able to set with setWhen).

Leave a Comment