为什么我们在通知中使用 PendingIntent?

Why do we use PendingIntent in notifications?

我对 android 应用程序开发有些陌生。我想知道为什么我们在创建通知时使用 pendingIntent

我已在文档中阅读此内容(https://developer.android.com/training/notify-user/navigation):

this page describes how you set up a PendingIntent for your notification's action so it creates a fresh task and back stack

但是,我无法理解 PendingIntent 如何创建新任务和返回堆栈。

感谢所有帮助。谢谢!!

我想用一种非常简单的方式来解释。 Pending 表示有待处理的东西,如您所见,它是 Pending Intent,这意味着有一个 intent 正在等待执行某些操作。就像如果您点击通知会带您到屏幕的某个位置,导航正在等待您点击通知。希望你明白了!再见。

I was wondering why we use pendingIntent while creating notifications.

阅读the PendingIntent documentation。具体是这个位:

A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it.

换句话说,您将 PendingIntent 用于通知,因为通知可以无限期地停留在用户的通知区域,在此期间您的应用可能已被终止。

However, I can't wrap my head around how a PendingIntent creates a fresh task and back stack.

没有。你做到了,as explained in the very article you linked