exitapplication ends the app?

ilkrkls

Member
Licensed User
Longtime User
Hi,
I hope this is the section to ask this.
In previous versions I did not have this problem.
With release 1.9, exitapplication command does not end the application, but ends the current activity (I think).
Or am I doing something wrong?
I wrote an example code;
First activity starts, press the button to start the second activity while the first one is alive. Then press the back button to open the exit dialogue.
But the app does not end, even if I put an activity.finish line before exitapplication line.
 

Attachments

  • exitapp.zip
    294.7 KB · Views: 426

klaus

Expert
Licensed User
Longtime User
Attached you find a working solution using a process global variable which is set to true in the second activity and the program is closed in the main activity.
I tested your code also with B4A 1.8, same problem.

Best regards.
 

Attachments

  • exitapp1.zip
    7.6 KB · Views: 446
Upvote 0

ilkrkls

Member
Licensed User
Longtime User
Thank you Klaus. I will try that.
But isn't exitapplication command supposed to end all the activities and exit the application?
 
Upvote 0

salmander

Active Member
Licensed User
Longtime User
Hi Klaus, How do you implement this in a project where there are tens of activities? Some of the activities are open but in background and some have been closed by using activity.finish in Activity_Pause event.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a further look at the subject and found following explanation.
The code in post#1 works with the condition to add systematically Activity.Finish just before starting another Activity.
As Erel posted, adding Activity.Finish when leaving an Activity doesn't need ExitApplication.

Best regards.
 
Last edited:
Upvote 0

ilkrkls

Member
Licensed User
Longtime User
Dear Klaus & Erel,

As Klaus suggested, I did put a "exitprog" variable.

I have three activities,
The first one is some settings, and I "activity.finish" it before I launch the second activity. But the first activity gives variables to the second activity, so although if I finish the first activity before opening the second, the program still runs in the background. So in the first activity, I put "secondactivity.exitprog=true" and then "ExitApplication" command.

The third activity however, must not close or reload the second activity and it also gives variables to the second activity. So, if I make changes in itand return to the second one, I simply "activity.finish" it. But if I want to close the app from the third one, I put "secondactivity.exitprog=true". So the second activity closes the app by "ExitApplication".

This is the workaround I found. Thank you for your help.
 
Upvote 0

ilkrkls

Member
Licensed User
Longtime User
Also, if I close all activities with activity.finish, the app runs in the background. And if there are variables in "first time" of activity load, these variables do not load when I rerun the app. As a result, weird things happen.
I had to delete "if first time=true" lines...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The process is kept in the background until the OS decides to kill it. This is how Android is designed. From my experience it works quite good.

And if there are variables in "first time" of activity load, these variables do not load
It is good that the variables are not reinitialized. You should correctly place your variables in Globals or in Process_Globals based on their usage.

See this tutorial: http://www.b4x.com/forum/basic4andr...87-android-process-activities-life-cycle.html
 
Upvote 0
Top