Android: How to renew application from notification?

I'm trying to program my notification to resume my application, instead of just starting a new instance of my application ... I basically look for it to do the same thing as when I clicked the Home button, and the application resumed from there.

Here is what I am doing now:

void notifyme(String string){ String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.notification_icon; // icon from resources CharSequence tickerText = string + " Program Running..."; // ticker-text long when = System.currentTimeMillis(); // notification time Context context = getApplicationContext(); // application Context CharSequence contentTitle = *********; // expanded message title CharSequence contentText = string + " Program Running...";//expanded msg text Intent notificationIntent = new Intent(this, Main.class); PendingIntent contentIntent = PendingIntent.getActivity( this, 0, notificationIntent, 0); // the next two lines initialize the Notification, using the configurations // above Notification notification = new Notification(icon, tickerText, when); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); final int HELLO_ID = 1; mNotificationManager.notify(HELLO_ID, notification); } 

I guess the new Intent line is where the problem is ... any help would be appreciated!

+12
android
Oct 28 '10 at 22:35
source share
2 answers

you need to set flags

  notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

Also, if you never want the duplicate action to give it this attribute in the manifest

 android:launchMode="singleTask" 
+12
Oct 29 '10 at 0:00
source share

The selected answer did not work for me, but if someone else while viewing this, it worked for me: Resume application and stack from notification

0
Jan 27 '19 at 19:45
source share



All Articles