Android Question activity_keypress backbutton(solved)

ronell

Well-Known Member
Licensed User
Longtime User
B4X:
Sub activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        If Msgbox2("Do you want to close the app?", "Close App","Yes","Logout","No", Null)  = DialogResponse.POSITIVE Then
       
       
            Activity.Finish
           
   
        else if DialogResponse.CANCEL  Then
           
            Activity.LoadLayout("frmlogin")
           
       
        Else
   
        End If

        Return True
    End If

End Sub

having error when pressing logout(DialogResponse.CANCEL)


B4X:
Error Occured
An error has occured in
Sub: main_activity_keypress
(java line:357)
java.lang.RuntimeException:
Cannot parse: -3 as boolean
 

klaus

Expert
Licensed User
Longtime User
You should use this:
B4X:
Sub activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Private Answ As Int
        Answ = Msgbox2("Do you want to close the app?", "Close App","Yes","Logout","No", Null)
        If Answ = DialogResponse.POSITIVE Then
            Activity.Finish
        Else If Answ = DialogResponse.CANCEL  Then         
            Activity.LoadLayout("frmlogin")
        Else
  
        End If
        Return True
    End If
End Sub
 
Upvote 0
Top