在将用于通知的 pendingintent 中使用 FLAG_ONE_SHOT 是什么意思?有必要吗?

What is the meaning of use FLAG_ONE_SHOT in a pendingintent which will be used to a notification? Is it necessary?

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() 是在我点击通知时内部调用的吗?这个标志在通知中会变得毫无意义吗?

PendingIntent.FLAG_ONE_SHOT表示PendingIntent使用一次后将被删除。通常,如果系统中有其他引用,PendingIntent 可以挂起。

这个标志可以用来防止 PendingIntent 的多次使用,虽然我个人的经验是这个标志通常导致的问题多于它解决的问题。

您问的是:

Is pendingIntent.send() called internally when I clicks the notification?

是的,当您单击与 Notification 中的 PendingIntent 关联的 UI 元素时,基本上就是这样。