Android Question finish application from 3. or 4. activity

Pflichtfeld

Active Member
Licensed User
If I browse from main to Activity2 and then Activity3 the back key returns me to A2, then main (unless I have finished them after calling sub-Activity what I do not want here).
If I want a button on Activitiy3, which finishes the hole app: how is this easyly achieved?
should I call sub on A2, which finishes A2 and calls a Sub on main, which finishes main or is there another way?
Thank you
Thomas
 

drgottjr

Expert
Licensed User
Longtime User
you can jump back to main from 3. if 2 and 3 are, more or less, subservient to main, it might be convenient to exit whence you began.
there is also exitapplication. definitely not erel's favorite, but stick it in 3 somewhere and see what you get. allegedly goes against the spirit of android (whatever that may be). plus you may lose values that you might otherwise have stored for future reference in main. sometimes a single exit point can be useful. especially if you only have 1 assault rifle available to cover all the exits.
 
Upvote 0

Pflichtfeld

Active Member
Licensed User
Thank you drgottjr!
As I understood what I have read so far is: If I jump back to Main and finish main, the process starts activity 2 or 3 to continue the app, if they are not finished before.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
there is also exitapplication. definitely not erel's favorite
Because in Android, it is the user that should decide if an application ends (or Android). It (Android) is a user/operating centric OS, not a developer.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If you want something like an exitapplication that is compliant, then you (just one approach) keep track in what state your app is in. Sort of like logging in/out but without the user actually logging in or out. Your app can than use whatever logic it wants to to determine if the application is continuing a previous process or if it needs to start from the beginning. No exit application needed. And you won’t anger Android (by thinking your application has crashed - the result of an exitapplication)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Thank you drgottjr!
As I understood what I have read so far is: If I jump back to Main and finish main, the process starts activity 2 or 3 to continue the app, if they are not finished before.

not quite. main can't jump to 2 without main's starting 2. but 2 can finish and set main in motion simply by virtue of finishing (default behavior).
if you jump from 3 to main and call activity.finish, the other activities aren't called (unless you call them before calling activity.finish. but even then they'll all die once android senses a stillness in the air from your app.) when you go from 2 to 3, 2 stops (eventually). when you go from 3 to main, 3 stops (eventually). android kills them (in the spirit of android). if you call exitapplication, the process (which contains all the activities stops). this is what is against the spirit. but sometimes you gotta do what you gotta do. as i said, having 1 exit point (via activity.finish in main) is cleaner. you shouldn't have to use exitapplication. but it's there if you understand what's going on. whether or not you ever have to use it depends on why you think you have to. i don't see why you have to in this case. if you call activity.finish from 3 and 2 and main have been killed by the os, no harm, no foul. 3 dies and the others are already dead. if you call activity.finish from 3 and 2 is still alive, 2's your man. main is main for a reason, imho.

i've always returned to main from 2 or 3 because i believe in 1 exit. if you finish in 3, and 2 and main are dead, i don't think they come back to life. but android is what it is. if they do come back to life, then that makes things messy for you. you'll have to try it. worst case, you start main back up when you're done in 3 and then you finish up nice and clean in main, and andoird is happy. and if you want main to know that it came back from 3, you can set a global process variable that tells main "sentBy3 = true". when activity resume in main runs, you have it test the value of sentBy3. if false, main does what it normally does. if true, main knows that 3 finished up and wants to go home. main could then call activity.finish.
 
Last edited:
Upvote 0

Pflichtfeld

Active Member
Licensed User
if you jump from 3 to main and call activity.finish, the other activities aren't called (
I'll test this by calling a sub in main from 3 to finish main like
B4X:
CallSubDelayed(Finish_Me,"Main")
and hope 2 and 3 won't come back.
If it wont work I'll tell you.
 
Upvote 0
Top