Fadi Obaji Fadi Obaji - 10 months ago 70
Android Question

Android: Why use PendingIntent instead of Intent to start an activity?

I'm developing a news app, it gets the contents from the news website. I'm making a push notification service by using the new GoogleCloudMessaging technique, so i follow Google's official tutorial and i noticed that they used a PendingIntent, so here are my questions:

  1. What is a pending intent exactly ?

  2. And how does it differ from the normal intent ?

  3. Can i replace it with a normal intent and still can pass my data (extras) to my desired activity ?

  4. Is there any differences in usage and implementation between the two of them ?

Thanks in advance.


A pending intent has a special purpose- it can be passed to other apps to allow them to call into you with the same permissions of your app that other app might not have. PendingIntent should only be used when you're passing it off to another application, such as when setting a Notification (the Notification app can launch your activity via the pending intent). There's no reason to use it internally within your app.