Android Question Error in dialog.response

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello All,
I have a small code that questions the user to confirm to exit the Application and I am getting a strange error, saying that the compiler cannot parse the dialog response

B4A 7.30

The Error in the Log window is :
B4X:
Error occurred on line: 1559 (Main)
java.lang.RuntimeException: Cannot parse: -1 as boolean
    at anywheresoftware.b4a.BA.parseBoolean(BA.java:591)
...

The code that Causes it:

B4X:
Sub btnExit_Click
 
    Msgbox2Async("Exit Application ?","TP-614","Yes","","No",Null,False)
 
    If DialogResponse.POSITIVE Then
        Activity.Finish
    Else
        Return
    End If
End Sub

Thanks
 

Cableguy

Expert
Licensed User
Longtime User
B4X:
Sub btnExit_Click
 
    Dim myResponse as Boolean = Msgbox2Async"Exit Application ?","TP-614","Yes","","No",Null,False)
 
    If myResponse Then
        Activity.Finish
    Else
        Return
    End If
End Sub

This is pseudo code just to get you on the right track
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
Now I get

B4X:
java.lang.RuntimeException: Cannot parse: android.app.AlertDialog@844d73 as boolean

It wants booleans but refuses it ?
 
Last edited:
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
from docu
B4X:
Msgbox2Async("Question?", "Title", "Yes", "Cancel", "No", Null, False)
Wait For Msgbox_Result (Result As Int)
If Result = DialogResponse.POSITIVE Then
  '...
End If
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
B4X:
Msgbox2Async("Deseja Sair da Aplicação ?", "Zarph TP-6X4", "Sim", "", "Não", Null, False)
    Wait For Msgbox_Result (Res As Int)
    If Res = DialogResponse.POSITIVE Then
        ExitApplication
    End If

Worked
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

kisoft

Well-Known Member
Licensed User
Longtime User
B4X:
Msgbox2Async("Deseja Sair da Aplicação ?", "Zarph TP-6X4", "Sim", "", "Não", Null, False)
    Wait For Msgbox_Result (Res As Int)
    If Res = DialogResponse.POSITIVE Then
        Activity.finish
    End If
ExitApplication is a mistake. Android can treat the application as if it hung up.
 
Upvote 0
Top