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

1715 questions
570
votes
17 answers

What is an Android PendingIntent?

I am a newbie to Android. I read the Android Documentation but I still need some more clarification. Can anyone tell me what exactly a PendingIntent is?
Rakesh
  • 14,229
  • 12
  • 36
  • 60
199
votes
10 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,375
  • 5
  • 18
  • 16
143
votes
6 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 =…
134
votes
3 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,108
  • 12
  • 32
  • 61
131
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
  • 11,791
  • 12
  • 60
  • 86
124
votes
6 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
  • 106,412
  • 122
  • 641
  • 1,128
91
votes
13 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
80
votes
2 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
  • 11,793
  • 3
  • 28
  • 36
77
votes
4 answers

How to remove notification from notification bar programmatically in android?

Anybody have idea how can we remove notification from application programmatically which is called using Pending intent. I have used to cancel notification using following method. AlarmManager…
52
votes
6 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) …
51
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() { …
50
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…
44
votes
6 answers

Pending intent in notification not working

Below is my block of code which should open NotificationActivity when the notification is tapped on. But its not working. private void setNotification(String notificationMessage) { Uri alarmSound =…
prashantwosti
  • 885
  • 2
  • 7
  • 17
40
votes
4 answers

Delete alarm from AlarmManager using cancel() - Android

I'm trying to create and delete an alarm in two different methods which are both called at different moments in the application logic. However when I call AlarmManager's cancel() method, the alarm isn't deleted. Here's my addAlarm() Method…
Mike Bryant
  • 2,345
  • 8
  • 36
  • 58
39
votes
8 answers

Extract notification text from parcelable, contentView or contentIntent

So I got my AccessibilityService working with the following code: @Override public void onAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) { …
Force
  • 5,986
  • 6
  • 50
  • 81
1
2 3
99 100