Android: How to use MessagingStyle for notifications without caching messages
One of the best practices for a messaging application is to use MessagingStyle for notifications. Android provides the style starting in API level 24, that makes notifications cleaner:

The following code shows how to apply the MessagingStyle class:
You can see that all the messages that we want to display in the notification we add during the creation of the notification. But imagine that after the notification is displayed you receive a new message and you want to append it to the notification. There is no way to edit a displayed notification, therefore you have to replace it with a new one, but for this you need all messages from the active notification. So we have a problem — how can we obtain these messages? Do we need to cache them? Fortunately, no. Android provides method for restoring the style with the messages from notification:
We look for the active notification using a notification id and extract MessagingStyle from it. The extracted style contains the messages we need, so all we have to do is add a new message to the style and update the active notification using a new one with the up-to-date style.
You might prefer to reuse an active notification’s builder instead of creating it from scratch, for example, in case of using direct reply:

Also make sure that updating a notification with your reply is silent(without sound, vibration and light). You can turn on the flag FLAG_ONLY_ALERT_ONCE calling recoveredBuilder.setOnlyAlertOnce(true) to make it noiseless.
