Android Question Trying to use Msgbox2Async in Activity_KeyPress

Discussion in 'Android Questions' started by asales, Oct 12, 2019 at 8:12 PM.

  1. asales

    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):
    Code:
    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"""NullTrue)
            
    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:
    Code:
    ** 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.
     
  2. mc73

    mc73 Well-Known Member Licensed User

    You can try:
    Code:
    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"""NullTrue)
         
    Wait For Msgbox_Result (Result As Int)
         
    If Result=DialogResponse.POSITIVE Then
             
    Activity.Finish
         
    end if 
    End Sub
     
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