How to update Notification

2019-06-08 13:42发布

问题:

I have a Notification in my android application. And this Notification has a progress bar.

My question is: if I update progress in the progress bar of my Notification, should I pass the SAME instance of Notification or create a new instance of Notification?

should I do this:

mNotification = new Notification(..); // create in the constructor of my activity

getNotificationManager().notify(TAG, FILE_UPLOAD_ID, mNotification);

or

getNotificationManager().notify(TAG, FILE_UPLOAD_ID, new Notification(...) );

回答1:

The same.

public void notify (String tag, int id, Notification notification) Since: API Level 5

Post a notification to be shown in the status bar. If a notification with the same tag and id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information. *

Parameters tag A string identifier for this notification. May be null. id An identifier for this notification. The pair (tag, id) must be unique within your application. notification A Notification object describing what to show the user. Must not be null.