Android Question Resumable subs cannot return a value.

panagiotisden2

Active Member
Licensed User
Longtime User
i want to show a dialog in Activity_KeyPress if the back button was pressed with a msgboxasync and a wait for but i get this error. I was previously doing it with a msgbox result and i wanted to convert it to msgboxasync. isn't it possible?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can do it with this code:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
   If KeyCode = KeyCodes.KEYCODE_BACK Then
     HandleBackKey  
     Return True  
   End If
   Return False
End Sub

Private Sub HandleBackKey
  Msgbox2Async(Message, "Close?", "Yes", "No", "", Null, False)
   Wait For MsgBox_Result (Result As Int)
   If Result = DialogResponse.POSITIVE Then
     Activity.Finish
   End If 
End Sub

It is better than showing a modal dialog in the KeyPress event.
 
Upvote 0

panagiotisden2

Active Member
Licensed User
Longtime User
Thank you Erel, very clever solution. It fits my needs
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…