what is the exact difference between intent and pe

2020-02-07 18:11发布

Possible Duplicate:
What is Pending Intent?

I'm confused about intent and pending intent.
Can anyone explain what exactly is the difference between both? I've searched on SO, I found this link but it didn't meet with my need: https://stackoverflow.com/questions/5633810/what-is-difference-between-an-intent-and-a-pending-intent.

i know Pending intent is an intent which will start later on. Normal intent is started at the time it is passed to startActivity(intent) or StartService(intent).

1条回答
倾城 Initia
2楼-- · 2020-02-07 18:57

PendingIntent

A description of an Intent and target action to perform with it. Instances of this class are created with getActivity(Context, int, Intent, int), getBroadcast(Context, int, Intent, int), getService(Context, int, Intent, int); the returned object can be handed to other applications so that they can perform the action you described on your behalf at a later time.

By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity). As such, you should be careful about how you build the PendingIntent: often, for example, the base Intent you supply will have the component name explicitly set to one of your own components, to ensure it is ultimately sent there and nowhere else.

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. If the creating application later re-retrieves the same kind of PendingIntent (same operation, same Intent action, data, categories, and components, and same flags), it will receive a PendingIntent representing the same token if that is still valid, and can thus call cancel() to remove it

INTENT

An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service.

An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed. The primary pieces of information in an intent are:

action -- The general action to be performed, such as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc. data -- The data to operate on, such as a person record in the contacts database, expressed as a Uri.

查看更多
登录 后发表回答