afb
afb

Reputation: 35

make notification when clicking app bring to front

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?

Upvotes: 0

Views: 1176

Answers (2)

Viswanath Lekshmanan
Viswanath Lekshmanan

Reputation: 10083

Try this

PendingIntent pen = PendingIntent.getActivity(Timer.this, 0, intent,Intent.FLAG_ACTIVITY_TASK_ON_HOME);

Upvotes: 0

mcnicholls
mcnicholls

Reputation: 846

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.

Upvotes: 1

Related Questions