Android Question app not closing

elitevenkat

Active Member
Licensed User
Longtime User
hi
following is the code in main activity
B4X:
Sub Activity_KeyPress (key As Int) As Boolean
  
    
    Dim rs As Int
    If key=KeyCodes.KEYCODE_BACK Then
        rs= Msgbox2("Close app  "    ,"Going Back","Yes","Cancel","No",Null)
        If rs=DialogResponse.POSITIVE Then
          
            StopService(Starter)
            Activity.Finish
            ExitApplication
          

        Else
            Return True
        End If
    End If
    ' Returning False signals the system to handle the key
    Return False
End Sub

in starter module

B4X:
Sub JobDone(Job As HttpJob)

    If Job.Success = False Then
        Log("Error: " & Job.ErrorMessage)
        'Msgbox("No net connection","Error")
        ToastMessageShow("No net connection",True)

      
        StopService(Me)
      
        Job.Release
        
        ExitApplication
    Else
        If Job.JobName = "DBRequest" Then

when back key is pressed the app is asking for the msg prompt but does not close
In starter service, if there is no net connection, i want to exit the app. however it keeps on running

what is wrong in the code ?
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Activity_KeyPress (key As Int) As Boolean
 
    
    Dim rs As Int
    If key=KeyCodes.KEYCODE_BACK Then
        rs= Msgbox2("Close app  "    ,"Going Back","Yes","Cancel","No",Null)
        If rs=DialogResponse.POSITIVE Then
          
            StopService(Starter)
            Activity.Finish
            ExitApplication
            Return True ' RETURN TRUE to consume the Event---
          

        Else
        End If
    End If
    ' Returning False signals the system to handle the key
    Return False
End Sub
 
Upvote 0
Top