Android Question Trying to use Msgbox2Async in Activity_KeyPress

asales

Well-Known Member
Licensed User
I have this code ,which I want to show the message when the user press the back button (keycode_back):
B4X:
Sub Activity_KeyPress (KeyCode As Int) As ResumableSub
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Msgbox2Async("Do you need to click in the button!","Interruped", "Continue", "Cancel", "", Null, True)
        Wait For Msgbox_Result (Result As Int)
        If Result <> DialogResponse.POSITIVE Then
            Return True
        End If
    
        Activity.Finish

        Return True
    End If

    Return False
End Sub
but I get this error:
B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main$HandleKeyDelayedrunDirectly (java line: 230)
java.lang.ClassCastException: anywheresoftware.b4a.keywords.Common$ResumableSubWrapper cannot be cast to java.lang.Boolean
    at b4a.example.animate1.main$HandleKeyDelayed.runDirectly(main.java:230)
    at b4a.example.animate1.main$HandleKeyDelayed.run(main.java:227)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
What could be the problem?

Thanks in advance for any tip.
 

mc73

Well-Known Member
Licensed User
You can try:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
 
  If KeyCode = KeyCodes.KEYCODE_BACK Then
      openMsgBox
      return true 
  else
      return false
  end if        
End Sub

Sub openMsgBox
   Msgbox2Async("Do you need to click in the button!","Interruped", "Continue", "Cancel", "", Null, True)
     Wait For Msgbox_Result (Result As Int)
     If Result=DialogResponse.POSITIVE Then
         Activity.Finish
     end if 
End Sub
 
Top