Questions tagged [android-pendingintent]

An Android class that provides a description of an Intent and target action to perform with it

From the PendingIntent API:

A description of an Intent and target action to perform with it. Instances of this class are created with getActivity(Context, int, Intent, int), getActivities(Context, int, Intent[], int), getBroadcast(Context, int, Intent, int), and 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.

Useful links

1881 questions
622
votes
18 answers

What is an Android PendingIntent?

I read the Android Documentation but I still need some more clarification. What exactly is a PendingIntent?
Rakesh
  • 14,997
  • 13
  • 42
  • 62
246
votes
22 answers

How to resolve "Missing PendingIntent mutability flag" lint warning in android api 30+?

As soon as I updated the target SDK to 30+ (Android R or later), a lint warning Missing PendingIntent mutability flag appeared on my PendingIntent.FLAG_UPDATE_CURRENT flag when I want to define PendingIntent. How should I handle this lint with no…
Amir Hossein Ghasemi
  • 20,623
  • 10
  • 57
  • 53
217
votes
11 answers

Calling startActivity() from outside of an Activity?

I'm using an AlarmManager to trigger an intent that broadcasts a signal. The following is my code: AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, Wakeup.class); try { PendingIntent pi =…
Tom G
  • 2,595
  • 5
  • 20
  • 16
149
votes
7 answers

Notification passes old Intent Extras

i am creating a notification inside a BroadcastReceiver via this code: String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); int icon =…
146
votes
4 answers

PendingIntent does not send Intent extras

My MainActicity starts RefreshService with a Intent which has a boolean extra called isNextWeek. My RefreshService makes a Notification which starts my MainActivity when the user clicks on it. this looks like this: Log.d("Refresh",…
maysi
  • 5,457
  • 12
  • 34
  • 62
144
votes
8 answers

Intent - if activity is running, bring it to front, else start a new one (from notification)

My app has notifications, which - obviously - without any flags, start a new activity every time so I get multiple same activities running on top of each other, which is just wrong. What I want it to do is to bring the activity specified in the…
urSus
  • 12,492
  • 12
  • 69
  • 89
140
votes
5 answers

What's "requestCode" used for on PendingIntent?

Background: I'm using PendingIntent for alarms via AlarmManager. The problem: At first I thought that in order to cancel previous ones, I must provide the exact requestCode that I've used before to start the alarm. But then I've found out I was…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
97
votes
14 answers

PendingIntent works correctly for the first notification but incorrectly for the rest

protected void displayNotification(String response) { Intent intent = new Intent(context, testActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); Notification…
user350617
97
votes
5 answers

How to remove notification from notification bar programmatically in android?

How can one remove a notification from an application programmatically, which is called using Pending intent? I have used to cancel notification using following method: AlarmManager am=(AlarmManager)getSystemService(Context.ALARM_SERVICE); Intent…
89
votes
3 answers

Get list of active PendingIntents in AlarmManager

I there a way to get a list of the active PendingIntents in a device? I am starting to work with AlarmManager and I like to see if my PendingIntents are created and removed correctly. It would also be nice to see what other PendingIntents are there,…
BrainCrash
  • 12,992
  • 3
  • 32
  • 38
67
votes
11 answers

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified

App crashes at runtime with the following error : java.lang.IllegalArgumentException: maa.abc: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider…
62
votes
8 answers

Android Notification PendingIntent Extras null

I am trying to send information from notification to invoked activity, while from my activity I got null. The code for notification is: private void showNotification() { Intent resultIntent = new Intent(this, MainActivity.class); if (D) …
59
votes
5 answers

How to open fragment page, when pressed a notification in android

I am trying to open a fragment when I press a notification in the notification bar. My app structure is: a base activity with a nav drawer menu some fragment that are opened from menu b.setOnClickListener(new OnClickListener() { …
57
votes
8 answers

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent, On AlarmPingSender

Problem Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. I got it after updating target SDK to 31. the error always come after AlarmPingSender. But i dont know any…
53
votes
2 answers

Android cannot pass intent extras though AlarmManager

I am trying to put an extra message in my intent to pass to AlarmManager to be triggered at a later time. My onReceive triggers correctly but extras.getString() returns null Setup: public PendingIntent getPendingIntent(int uniqueRequestCode, String…
1
2 3
99 100