Notification使用误区
2017-11-27 18:00
197 查看
Updating notifications
To set up a notification so it can be updated, issue it with a notification ID by callingNotificationManager.notify().
To update this notification after you've issued it, update or create a
NotificationCompat.Builderobject,
build a
Notificationobject from it, and issue the
Notificationwith
the same ID you used previously. If the previous notification is still visible, the system updates it from the contents of the
Notificationobject.
If the previous notification has been dismissed, a new notification is created instead.
Caution: The system applies a rate limit to updating notifications. If you post updates to a notification too frequently, the system may drop some notifications.Note: You can optionally call
setOnlyAlertOnce()to
only turn on a notification sound, vibration, and ticker if the notification is not already showing.
The following snippet demonstrates a notification that is updated to reflect the number of events that have occurred. It stacks the notification, showing a summary:
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Sets an ID for the notification, so it can be updated int notifyID = 1; mNotifyBuilder = new NotificationCompat.Builder(this, CHANNEL_ID) .setContentTitle("New Message") .setContentText("You've received new messages.") .setSmallIcon(R.drawable.ic_notify_status); numMessages = 0; // Start of a loop that processes data and then notifies the user ... mNotifyBuilder.setContentText(currentText) .setNumber(++numMessages); // Because the ID remains unchanged, the existing notification is // updated. mNotificationManager.notify( notifyID, mNotifyBuilder.build()); ...
=======================================
notification 更新一次就new 一次。。。不需要复用!!!!!!
否则会造成 TransactionTooLargeException !!!
相关文章推荐
- Notification(一)——基础知识使用示例
- 山地自行车零件选择及使用误区
- iPhone开发之NSNotificationCenter(通知)的使用方法
- NotificationManager和Notification的使用总结
- NotificationManager和Notification的使用总结
- 使用maven常见的误区与解决办法!
- 几个字符串的误区,以及setlocale函数的使用
- iOS下的Notification的使用
- iOS开发之:NSNotificationCenter(通知)的使用方法
- UIButton使用误区
- 使用OpenSSL发送IOS推送通知 Apple Push Notification
- android Notification 的使用
- Android 使用Notification(通知)
- Android状态栏提醒(Notification,NotificationManager)的使用!
- Hello Android - NotificationManager和Notification的使用总结
- Notification在不同版本下的使用贴…
- 个推服务端api使用误区
- NotificationManager 和Notification的使用总结(转)
- Notification 使用详解
- Android NotificationManager 和Notification的使用总结