Android : 为什么要使用群组通知?

Android : why use a group notification?

我希望我的应用程序使用 Android 通知,所以我已经玩了一段时间以了解它们是如何工作的。

经过一些尝试并阅读了有关它的 android 文档,我不明白当我有串行通知时需要使用组通知而不是唯一通知:如果我事先检测到我有多少通知如果有多个通知,只需要显示和推送一个通知,说应该有多少个通知,它的行为不会像标准的组通知一样吗?

Android Wear 有成组或堆叠的通知。引用我自己,来自 this book:

If you are writing an email client, and you want to use a Notification to let the user know about new email messages, you do not want to raise a separate Notification for each email. Users will come to your home with pitchforks and torches... and not to help you with farming.

Instead, the vision is that you update an existing Notification with new content. For example, you might start with a regular Notification for the first received email. Then, when the second one comes in, you replace that Notification with one that has a simple summary ("2 messages are in your inbox!"), plus perhaps an InboxStyle "big" Notification variant that could show the subject lines for both of those messages.

Android Wear devices, however, add an interesting wrinkle: you want the Notification to be informative about the event itself. You want the user to be able to make an informed decision about whether they should pull out their primary device to read the new messages, and that decision is only partly based on how many messages there are. Users will want to know more about the outstanding messages (sender and/or subject line) to help them make that decision... at least to a point. If there are 57 unread messages, users may get frustrated dealing with all of those as individual items on the wearable itself.

The pattern here, then, takes advantage of some "group" capabilities added to NotificationCompat:

  • Raise one "summary" Notification, that will only be shown on the primary device, with the same sort of "2 messages are in your inbox!" information that you would have used without considering Wear

  • Raise individual notifications for individual messages that will appear on the Wear device

  • Collect all of those in a "group", so the primary device shows only the summary and the Wear device shows only the individual ones