0

Activity A is the home page of my application.

A -> B -> C

C starts A with FLAG_ACTIVITY_CLEAR_TOP to get the home page A correctly. This works fine and the stack simply becomes,

A

But B can be invoked directly using Notification Manager.

B -> C -> A

So even I use FLAG_ACTIVITY_CLEAR_TOP flag while starting A in C, the B and C still exists in Stack before A(home page) and on pressing back button from A, it goes back to B and C.

I dont want this behavior. On starting activity A from C, The stack only should have A. How canI do this?

Sathesh
  • 6,323
  • 6
  • 36
  • 48
  • you can close it using activity results, or just call `finish()` when you no longer want it, aka when exiting B. – IAmGroot Jan 24 '13 at 20:13
  • If I need to finish, then I have to finish both B and C so that pressing back on A will return to Android Home. But I dont want to finish B on starting C because I need C to go back to B using back button. – Sathesh Jan 24 '13 at 20:20
  • Then use activity result. http://developer.android.com/training/basics/intents/result.html That way you can chain close a set of activities, if you want to. – IAmGroot Jan 24 '13 at 20:35

2 Answers2

0

If you don't care about navigation, you can define both B and C as android:noHistory

BTW. I asked at some moment kind-of related question. You may be intresting to take a look at it: How to always start from a startup activity on Android?

Community
  • 1
  • 1
Victor Ronin
  • 22,758
  • 18
  • 92
  • 184
  • No. I need to go back from C to B on pressing back button. I will look on your thread. – Sathesh Jan 24 '13 at 20:26
  • Take a look at FLAG_ACTIVITY_CLEAR_TASK (http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TASK) . You can se this flag and it will clear the task (all activities in the stack) – Victor Ronin Jan 24 '13 at 20:28
  • @VictorRonin `FLAG_ACTIVITY_CLEAR_TASK` is only available from API level 11 (Android 3.0) – David Wasser Mar 21 '13 at 11:14
0

I would suggest that you start ActivityA (instead of ActivityB) from the notification, since you obviously want that activity to always be the root activity in your task. Add an extra to the Intent that gets passed to the Notification. Then, in onCreate() of ActivityA, you should check if the extra is present and if so, immediately start ActivityB. This should give you the navigation behaviour that you want.

David Wasser
  • 93,459
  • 16
  • 209
  • 274