3

Support App starts activity A, then A starts activity B and finishes itself. After that activity B starts activity C.

Now the stack contains B and C, with C at the top.

Then I click a button in activity C, and want it to clear B and C and start activity A, i.e. I want activity A to be the only activity in the stack. How can I make it?

Edit: I made a test to use FLAG_ACTIVITY_CLEAR_TOP. But it didn't work in my case, because activity A is not running when button in activity C is clicked.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user256239
  • 17,717
  • 26
  • 77
  • 89

1 Answers1

3

Set the FLAG_ACTIVITY_CLEAR_TOP flag on your intent to start activity A.

Edit: Is there a reason you can't leave A going? Then you could do as suggested.

Otherwise, another (more complicated) option:

In B start C forResult. When A is started from C, you could finish C with a result indicating to B to also exit.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
  • 1
    Android doc says: "If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent. " But in my case, activity A is not running, is FLAG_ACTIVITY_CLEAR_TOP still working? – user256239 Jul 26 '10 at 20:59
  • Thanks. I decided to keep activity A running. – user256239 Jul 26 '10 at 22:16