Android Question leave the app by clicking a button

sultan87

Active Member
Licensed User
Longtime User
Hello,
I want to leave the app by clicking a button
activity.finish closes the activity but not the app
how to do ?
Best regards
 

DonManfred

Expert
Licensed User
Longtime User
- Create a process global variable (boolean (false when creating the main activity))
- Set the variable to TRUE when clicking your exitbutton
Additional use Activity.finish

In EACH Activity (in Activity resume) check the boolean if it is true. starting in your main activity.
If it is true then call Activity.finish.
If it is false then you can use the activity like normal...


Asuming you go from main to act2 to act 3 to act4 to act5
Normally you would use back key to go back to act4 (and leaving act5)
Then you would use back key to go back to act3, then go back to act2 and then back to main.

Now (using the new global var)

You press the button in act5. Activity.finish is called in your buttonsub and the global var is set to TRUE
Android will go back to your act4. Here you have the new check in activity_resume. Note the global var is TRUE here... Activity.finish is called
Android will go back to your act3. Here you have the new check in activity_resume. Note the global var is TRUE here... Activity.finish is called
Android will go back to your act2. Here you have the new check in activity_resume. Note the global var is TRUE here... Activity.finish is called
Android will go back to your main activity. Here you have the new check in activity_resume. Note the global var is TRUE here... Activity.finish is called and your app will be terminated cause you closed all activities.

Never tried this but theoretical it should work like this.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Additional:

If you know you dont want to come back to the activity which is actualy running then you can do something like this (in this example i´ll go from act3 to act4. But i ont want to come back to act3.

B4X:
Activity.finish
startactivity(act4)

act3 will be killed and act4 will be started... If you now use the backkey in act4 then you will go back to act2 (act3 is not in the stack)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…