Search code examples
androidandroid-activityactivity-finish

Android - finish activity and exit app


I have an application which consists 3 activities - lets call them A, B & C. From activity A You can get to activity B, from B to C and from C to A (By pressing the back button).

On activity A I have an exit button (I know it`s not recomandded on android, but a lot of users are asking for it, so I decided to add it).

Anyway the problem is that: activity B has a timer, when the timer is finished it starts an intent that starts activiy C and calls finish() on activity B.

When the user then press back on activity C he gets to activty A - and then when he presses the exit button (this button only preforms finish()), it pops up activity B again. How can I prevent it from happen?

Thanks!


Solution

  • I'm not sure I understand how you end up at A when going back from C. Shouldn't it go back to B (logically, I mean. I know you want it to go to A)? In fact, that seems to kind of be what's happening. B is getting relaunched, but A appears on top of it, so that when you finish A, B (which was under it) is now shown.

    It sounds like you don't want B to be part of the history stack, so maybe when you launch B, you should launch it with the no history flag.