2

I ran into a strange problem today : I have 3 activites : A, B and C.

A starts B then finishes. B starts C then finishes. C is the only one running. And guess what happens when I call finish() on C (I have an exit app button) ? B is automatically created

So I did something : on B's onStart, if a certain static flag is set up, B call finish on itself. And what happened ? A was automatically created !

I finally got around that by calling finish() on A's start too if the flag is set but this was somehow a nightmare.

NB : I was 100% sure that C was the only one running when I pressed the exit button, thanks to logs on onDestroy() etc. I was also sure that there was no thread / timer running in the background etc. The proof is that A was magically created when I forced killed B, but was not created before.

NB 2 : I know the exit button is not the good thing on Android but the app is running in a kiosk on a special hardware support and users don't have access to home button and back arrow etc, hence the exit button in the admin part of the app

Edit :

// B.java:

xxx.onClick() { startActivityForIntent(B.this, C.class); finish();}

// same for A.java with B

// C.java exit.onClick { finish(); }

A is the entry point activity of the app

Thomas
  • 8,306
  • 8
  • 53
  • 92
  • 2
    Could you post some of the relevant parts of your code? – vipluv Feb 03 '15 at 19:15
  • @vipluv what parts specifically ? I would like to keep the question short – Thomas Feb 03 '15 at 19:32
  • *that* is a good question, as well. :-P Maybe the part where B starts C and finishes, to begin with? – vipluv Feb 03 '15 at 19:33
  • Is this not to do with the back stack preserving the previous activities? – Duncan Hoggan Feb 03 '15 at 19:35
  • I mean if you climb up a tree and cut the branch you are sitting on you will fall to the previous branch :P – Duncan Hoggan Feb 03 '15 at 19:36
  • @Duncan that shouldn't happen if he's calling finish() on the previous activities after starting the next one, right? – vipluv Feb 03 '15 at 19:40
  • @vipluv I have edited. If you were expecting other code from reading my question could you please tell me what part was not clear (Im not a native English speaker) and often people ask me to put in more code – Thomas Feb 03 '15 at 19:43

1 Answers1

0

Ok. Apparently this behaviour is normal: Android wakes up the previous activity on the activity stack if you try to exit using finish(); this is because the OS wants your application to survive unexpected situations like phone-calls interrupting the user.

See this answer: Finish all previous activities.

Try adding android:noHistory="true" for all your activities in their xml files.

That, or try some of the methods mentioned in the answer above.

Community
  • 1
  • 1
vipluv
  • 607
  • 5
  • 8