Is it possible to use startActivityForResult() from a status bar notification?
Say I have an activity A, which on some event starts activity B using startActivityForResult(). Now when it is in the background, on the event it shows a notification. Now on selecting the notification, how do i start activity B for result?
I do realize that activity A should have a service that runs in the background, but i guess the same question would apply even in that case.
Here’s the code for the notification. This is in the Activity A.
Notification notification = new Notification(R.drawable.ic_launcher, "New Notification", System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
CharSequence contentTitle = "My Notification Title";
CharSequence contentText = "My Notification Text";
Intent notificationIntent = new Intent(this, ActivityB.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);
nm.notify(1, notification); //1 = id
I think that you should just start the activity A from the activity B when the activity B is opened by opening the notification and then closed.
You can pass the return value in the intent that you use to start the activity A from the activity B.