Android Question How to kill all activities in the app?

Beja

Expert
Licensed User
Longtime User
The tech advice is to let the OS kill them at its own convenience! but the problem is when I run the same app again,
it started from where it last closed, not from Main activity. and there's a lot of data in memory too.
 

achtrade

Active Member
Licensed User
Longtime User
I have this in my main activity

B4X:
Sub btnExit
   Activity.Finish
   ExitApplication 
End sub

but the device re-open my app and I don't want that, I need to finish it from cache and everywhere, It has to be reopen only by the user
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
I'm guessing that maybe you are using a service set to startat? If this is the case then you also need to cancel it otherwise it will still run at the predefined time.
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
Maybe I'm doing something wrong, but the way I do it, is calling activity.finish before launching the next activity, and I never had any problems, nor global variables lost.

So if I am in activity "ONE" and want to call activity "TWO" I always do

B4X:
Activity.finish
StartActivity ("TWO")

If I am In activity "TWO" and want to call Activity "THREE" I do

B4X:
Activity.finish
StartActivity ("THREE")

If I am in activity Three and want to call Activity one I do

B4X:
Activity.finish
StartActivity ("ONE")

Etc.

If I want to end the application then I do

B4X:
Activity.finish
ExitApplication

As only the currently activity is running then it exits correctly.

As I said, maybe this is wrong, but I have a stress tested app that works this way, and it is working very well
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi,
How do you use a finished activity's process globals' variables in an open activity?
 
Upvote 0

achtrade

Active Member
Licensed User
Longtime User
Use a process global variable as a flag to indicate that the app is quitting. Check the value of this variable in Activity_Resume of all activities.

If it is true then call Activity.Finish.

In the last activity (assuming that you know which activity is the first in the stack) you should call ExitApplication.

But what happen if the user is in the main activity (last activity) ? activity_resume isn't fire. This is what I have in the main activity:

B4X:
Sub Process_Globals
        dim blCloseApp=False as boolean
end sub

Sub Activity_Resume
   if blCloseApp then

      ' AGAIN ??????
      Activity.Finish
      ExitApplication 
   end if
end sub

Sub Activity_KeyPress(KeyCode As Int) As Boolean
    If  KeyCode = KeyCodes.KEYCODE_BACK Then
        Dim result As Int
        result = Msgbox2("Close App?", "Exit", "Yes", "", "No", Null)
        If result = DialogResponse.Positive Then  
            blCloseApp=True
            Activity.Finish
            ExitApplication 
        Else
            Return True
        End If
    End If
End Sub
 
Upvote 0
Top