What is the difference between Intent and Pending Intent.Basically I know Intent ,It is used when startActivity(intent), startService(intent) call and also used in putExtra().But Where I can use Pending Intent.Please clarify.
-
see this: http://stackoverflow.com/a/4812421/2668136 and this one: http://stackoverflow.com/a/15873786/2668136 – Blo Nov 27 '13 at 02:18
-
It is fine but can u explain with example,Above link said about permission difference between intent and pending intent Please explain in example which will used permission. – App Kart Nov 27 '13 at 02:25
2 Answers
Pending intent
is intent which will start later on.
Normal intent
is start at the time when passed to startActivity(intent) or StartService(intent)
A PendingIntent is a token that you give to another application (e.g. Notification Manager, Alarm Manager or other 3rd party applications), which allows this other application to use the permissions of your application to execute a predefined piece of code.
To perform a broadcast via a pending intent so get a PendingIntent via PendingIntent.getBroadcast().
To perform an activity via an pending intent you receive the activity via PendingIntent.getActivity().

- 22,342
- 9
- 83
- 103
A PendingIntent
is to Activity
, Broadcast
or Service
.
Why use PendingIntent
?
Because, for example, if you want to create an Bluetooth Intent
and you make it like this:
Intent myIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(myIntent);
You will not have the permission to enable Bluetooth
which is: android.permission.BLUETOOTH_ADMIN
, so you must to create a PendingIntent
and with it, you don't need to have permission in this new Intent
.
In other words: This allows the foreign application to use your application's permissions to execute a predefined piece of code.
It's a token that you give to another application (eg NotificationManager, AlarmManager or a third application).
You can start a new Activity: getActivity(Context context, int requestCode, Intent intent, int flags)
perform a Broadcast: getBroadcast(Context context, int requestCode, Intent intent, int flags)
or start a Service: getService(Context context, int requestCode, Intent intent, int flags)
"Note that the activity will be started outside of the context of an existing
activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the
Intent."
You can create new PendingIntent
or use existing one with flags
, see this answer: https://stackoverflow.com/a/15298131/2668136
See these tutorials for more informations:
1. Simple Launch Activity with PendingIntent
2. Alarm Service using AlarmManager
3. Android Notifications using NotificationManager
4. Using AlarmManager and BroadcastReceiver
The latter two are very simple and great.
Hope this is helpful and more comprehensible.