What is a Pending Intent?


#1

Hello Mark,

I came across the term Pending Intent while going through the chapter on Services and now Notifications but so far, I haven’t found a proper definition or explanation of it.
I just cant figure out how it is different from an intent and why we need to use a pending intent and not a regular intent while, lets say, creating a notification.
I have gone through all the questions on stackoverflow that relate to this topic, also have read some blog posts and watched a couple of youtube videos but In vain.

I wish you had explained it in greater length in the book and i would suggest that u append a paragraph or two at the right place, in order to make the readers (especially beginners) well acquainted with it just like the rest of the book I have gone through so far.

Thanks


#2

I haven’t found a proper definition or explanation of it.

PendingIntent is introduced (briefly) in the chapter on services (see page 799 of Version 8.11).

I just cant figure out how it is different from an intent and why we need to use a pending intent and not a regular intent while, lets say, creating a notification.

First, an Intent does not indicate what to do with it. Suppose that you did hand an Intent over to NotificationManager. What would NotificationManager do with it? Start an activity? Start a service? Send a broadcast? NotificationManager does not know. A PendingIntent not only holds an Intent but an indication of which of those three operations to perform on it.

Second, a PendingIntent also holds details of who created it. Security rules — such as communicating with non-exported components — are interpreted based on who created the PendingIntent, not who is using it (via send()). So, for example, NotificationManager would have no rights to send a broadcast to a non-exported receiver, but if you give it a broadcast PendingIntent with an Intent that identifies that receiver, now it can.

I wish you had explained it in greater length in the book

I will see what I can do.


#3

Please read above replies attached to yours.


#4

Doesn’t Intent also hold details of who created it?

No.

It takes in a context in its constructor.

Intent has many constructors. Few take a Context. None imply that the Intent holds onto the Context.

Umm, non-exported components?

I get into that stuff elsewhere in the book — see the “Export Only What’s Necessary” section in the “Miscellaneous Security Techniques” chapter, starting on page 2505 of Version 8.11.

what other applications is it talking about?

Technically, any other process.

So, does it serve as “other application”, whereas, to my knowledge, it is a class and not even an activity.

NotificationManager is a system service. Most, though not all, system services are APIs to core OS processes. The system service does relatively little in your own process, but instead passes your requests along to some other process. So, in the case of NotificationManager, it passes your notifications to a core OS process that is responsible for the system UI, which includes the status bar and notification shade.


#5

Thanks for a detailed reply.
Perhaps it is too technical for someone like me.


#6

Perhaps it is too technical for someone like me.

I am not certain what “it” is. If “it” is PendingIntent, then it is too technical for just about everyone, myself included.

There are lots of places in computer programming where we create “tokens” to pass around that represent things — PendingIntent is a type of token. Occasionally, finding out all of the details of how that token works is reasonable. Typically, it is not, perhaps due to complexity or lack of visibility (e.g., a Web service token, where somebody else wrote the Web service, so you do not have access to the code). In those cases, developers usually settle for learning how to create and use the tokens.


#7

Understandable!
I just wished I had more clarity on it.
Thanks anyway!