1

I'm setting a notification when my app goes to background.

I want to simulate the behaviour of pressing on it on the "Recent Apps" menu, when clicking on the notification.

  1. If the app went to background and still is "alive" go to the last activity
  2. If the app was killed in background start it again from scratch

Is there any flag to add to an intent to "go to the top activity" only knowing which is the app?

neteinstein
  • 17,529
  • 11
  • 93
  • 123
  • If your app goes into background by pressing home button then user will go the same page when he clicks on your app icon. He won't be taken to the first activity. Can you please explain your situation more clearly ? – Abhay Kumar Nov 28 '12 at 10:51
  • Yes. And by pressing the notification I want to do that. But how do I know the top activity of the stack? Must I send it when setting the notification? – neteinstein Nov 28 '12 at 11:08
  • when you send out a notification you can set it. will post the code if possible in some time. – Abhay Kumar Nov 28 '12 at 11:11

1 Answers1

1

As said here: How to open last activity from notification status bar?

Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
notificationIntent.setAction(Intent.ACTION_MAIN);

This notificationIntent will then be passed to pendingIntent for further use.

Provided: MainActivity is the very first activity when we launch our app and in AndroidManifest.xml it must contain IntentFilters of CATEGORY_LAUNCHER and ACTION_MAIN.

Community
  • 1
  • 1
Abhay Kumar
  • 1,582
  • 1
  • 19
  • 45
  • Yes. But how about handling the problem of the Application being killed when in background? When I use that code it will not start the application, but go to that specific activity... – neteinstein Nov 28 '12 at 11:39
  • dont finish the activity on back button pressed. so when the activity starts it will load from the saved state – Abhay Kumar Nov 28 '12 at 11:41
  • Whenever you have an application on background it can be killed... by the user or the OS – neteinstein Nov 28 '12 at 11:48
  • Look into this [link](http://stackoverflow.com/questions/9188412/how-to-open-last-activity-from-notification-status-bar) – Abhay Kumar Nov 28 '12 at 12:05