Android Question How to Yes or No Exit apk in Another activity

ronovar

Active Member
Licensed User
Longtime User
I have multiple activities...main_activity and menu_activity

i need when user press back button to display message "do you want to close apk?" and if yes is selected then it closes if no it stays in menu_activity....a added this in menu_activity but pressing No exits apk pressing Yes returns to previus activity (main_activity)

B4X:
'GET - KeyPressed
Sub Activity_KeyUp (KeyCode As Int) As Boolean
    'SELECT - Remote Code
    Select KeyCode
            
Case KeyCodes.KEYCODE_BACK
            'DISPLAY - Message       
            ExitResult = Msgbox2("Are You Sure That You Want To Close Application?", " Title", "Yes", "No", "", LoadBitmapSample(File.DirAssets, "logo.png", 36, 36))

            'CHECK - Response       
            If (ExitResult = DialogResponse.POSITIVE) Then
               'EXIT APK
                isFirst = True
                Activity.Finish
                ExitAppplication
                Return False
            Else
                  'STAY  IN CURRENT ACTIVITY - menu_activity
                  'Return True
            End If
    End Select
End Sub
 

ronovar

Active Member
Licensed User
Longtime User
The problem was that MsgBox2 needs to be used in
Sub Activity_KeyPress and i was using in
Sub Activity_KeyUp so when i press ok or cancel it was fired again keyup sub and apk crashes...now i put activity_keypress and is working as it should be.
 
Upvote 0
Top