Monday, 26 August 2013

Notification redirecting to the last visible Activity

Notification redirecting to the last visible Activity

I have an App with some Activities, where MyActivity is the main, and I
use this code to show a Notification from a Service:
Intent intent = new Intent(this, MyActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
intent, 0);
/*
* Set up removteView
*/
mBuilder = new NotificationCompat.Builder(this)
.setContentIntent(pendingIntent);
mNotiMan = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
mNoti = mBuilder.build();
mNoti.flags = Notification.FLAG_NO_CLEAR;
mNotiMan.notify(NOTI_ID, mNoti);
The part of interest is the Intent and the PendingIntent. If I click the
Notification from the Homescreen or another App, I will be redirected to
the last visible Activity of my App.
I would expect that a click on the Notification would only redirect me to
MyActivity, starting it if it's actually not in the ActivityStack. But it
doesn't matter which Activity was the last visible one when I left the
App, I will be redirected to it. This is exactly what I need but I don't
know why this is possible.
Can someone please explain this to me?

No comments:

Post a Comment