SuperFrog
SuperFrog

Reputation: 7674

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!

Upvotes: 2

Views: 1625

Answers (3)

Harsh Dev Chandel
Harsh Dev Chandel

Reputation: 763

You activity b is not finished thats what i can figure out it is still in running state so when all other actitivties are finished it shows up please chekc if it is finished or not

Upvotes: 0

kabuko
kabuko

Reputation: 36302

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.

Upvotes: 1

Paweł Obrok
Paweł Obrok

Reputation: 23164

Idea: set a isFinished field in your Application to true and call finish(). All activities check if isFinished in their onResume() and if true they finish().

Upvotes: 2

Related Questions