0

I want make a notification, that when clicked on it will bring my app from the background to the front. I am using the following code:

NotificationManager noma = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
PendingIntent pen = PendingIntent.getActivity(Timer.this, 0, intent, 0);
intent.putExtra("key", "trigerred");
String body = "This is a message";
String title = "This is title";
Notification no = new Notification(R.drawable.ic_launcher, body, System.currentTimeMillis());
no.defaults = Notification.DEFAULT_ALL;
no.setLatestEventInfo(this, title, body, pen);
noma.notify(uniqueID, no);

When I click on the notification that makes a new intent but I want the last created intent brought to the front. How i can do this?

Bali C
  • 30,582
  • 35
  • 123
  • 152
afb
  • 35
  • 5

2 Answers2

1

You need to set the FLAG_ACTIVITY_SINGLE_TOP flag on the intent that you pass to getActivity. This should bring you back to the all ready running activity when clicking your notification.

See here for a list of the different launch flags.

mcnicholls
  • 846
  • 5
  • 10
  • i do this but it dows not effect. may give me an example please? – afb Feb 05 '12 at 11:59
  • sorry, rereading the docs I think you need to set the FLAG_ACTIVITY_NEW_TASK flag. This flag will launch the Activity into a new task, but if a task with this Activity all ready exists then it will bring it to the foreground instead. – mcnicholls Feb 06 '12 at 10:37
0

Try this

PendingIntent pen = PendingIntent.getActivity(Timer.this, 0, intent,Intent.FLAG_ACTIVITY_TASK_ON_HOME);
nsgulliver
  • 12,655
  • 23
  • 43
  • 64
Viswanath Lekshmanan
  • 9,945
  • 1
  • 40
  • 64