Android Question How to kill all activities in the app?

Discussion in 'Android Questions' started by Beja, Mar 4, 2015.

  1. achtrade

    achtrade Active Member Licensed User

    I have this in my main activity

    Code:
    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
     
  2. RandomCoder

    RandomCoder Well-Known Member Licensed 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.
     
  3. achtrade

    achtrade Active Member Licensed User

    No, I don't have any service

    What else can be ?
     
  4. Erel

    Erel Administrator Staff Member Licensed 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.
     
  5. JTmartins

    JTmartins Active Member Licensed 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

    Code:
    Activity.finish
    StartActivity ("TWO")
    If I am In activity "TWO" and want to call Activity "THREE" I do

    Code:
    Activity.finish
    StartActivity ("THREE")
    If I am in activity Three and want to call Activity one I do

    Code:
    Activity.finish
    StartActivity ("ONE")
    Etc.

    If I want to end the application then I do

    Code:
    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
     
    RandomCoder and DonManfred like this.
  6. Beja

    Beja Expert Licensed User

    Hi,
    How do you use a finished activity's process globals' variables in an open activity?
     
  7. achtrade

    achtrade Active Member Licensed User

    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:

    Code:
    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
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Is the main activity the only activity in the stack? If yes then your code should work.
     
  9. achtrade

    achtrade Active Member Licensed User

    Yes, but is it ok to put the ExitApplication twice ?
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    As a general rule you should avoid using ExitApplication at all. However if you do want to use it then you can use it any number of times (it will only be called once ;) ).
     
    lemonisdead likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice