It is acceptable to update a Notification
from a worker thread because the Notification
does not live in your application’s process and hence you are not updating its UI directly. The Notification is maintained in a system process, and the Notification
‘s UI is updated through RemoteViews
(doc), which allows the manipulation of a view hierarchy that is maintained by a process other than your own. If you look at the source for Notification.Builder
here you can see that it is ultimately building a RemoteViews
.
And if you look at the source for RemoteViews
here you’ll see that when you manipulate a view it is really just creating an Action
(source) object and adding it to a queue to be processed. An Action
is a Parcelable
that is ultimately sent via IPC to the process that owns the Notification
‘s view, where it can unpack the values and update the view as indicated… on it’s own UI thread.
I hope that clarifies why it is OK to update a Notification
from a worker thread in your application.