在用于通知的未决意图中使用 FLAG_ONE_SHOT 的含义是什么?有必要吗?
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setContentIntent(pendingIntent);
是不是意味着我不能通过重复点击这个通知来多次跳转到mainActivity?当我单击通知时,pendingIntent.send() 会在内部调用吗?该标志在通知中是否变得毫无意义?
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setContentIntent(pendingIntent);
Does it mean that I can't jump to the mainActivity multiple times by repeatedly clicking this notification? Is pendingIntent.send() called internally when I clicks the notification? Does this flag become meaningless in the notifications?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PendingIntent.FLAG_ONE_SHOT
表示PendingIntent
使用一次后将被删除。通常,如果系统中存在其他对 PendingIntent 的引用,则 PendingIntent 可能会挂起。该标志可用于防止多次使用
PendingIntent
,尽管我个人的经验是该标志通常会导致比它解决的问题更多的问题。你问:
是的,这基本上就是当您单击与
Notification
中的PendingIntent
关联的 UI 元素时发生的情况。PendingIntent.FLAG_ONE_SHOT
means that thePendingIntent
will be deleted after it is used once. Normally, aPendingIntent
can hang around if there are other references to it in the system.This flag can be used to prevent multiple uses of the
PendingIntent
, although my personal experience is that this flag generally causes more problems than it solves.You asked:
Yes, that's basically what happens when you click on the UI element associated with the
PendingIntent
in theNotification
.