Bug? Weird WebView and MsgBox2 conflict

JohnC

Well-Known Member
Licensed User
I am using webview and trapping any urls that the user clicks on using the below event:

B4X:
Sub wv_OverrideUrl (Url As String) As Boolean

    Select Case Msgbox2(URL,"Display URL?","Yes","","No",Null)
        Case DialogResponse.POSITIVE
             'use intent to display the URL in an outside browser
    End Select

    Return True
End Sub
Running on Android 4.4, everything works fine. But if I run this same code on 7.1.1 and even if the user selects "No" (meaning the intent wasn't executed), when focus returns to the webview, the webview content/page is very unresponsive - doesn't scroll easily, and any subsequent loading of html into the webview again is not visible until the user touches inside the webview control - and even then, the webview page won't scroll. You need to exit the app completely and rerun it for the webview to work properly again, that is until the user clicks on another link and the problem comes back.

If I simply substitute MsgBox instead of MsgBox2, then the problem go away. So there is some kind of weird conflict between the WV and the use of MsgBox2 in this event.

I even tried using the MsgBox2Async version thinking that maybe the issue is with blocking code, but I can't because the wv_Override Sub returns a Boolean and can't be resumable :(

As a workaround, I replaced the MsgBox2 with this
B4X:
CallSubDelayed2(Me,"AskURL",URL)
so now the MsgBox2 is in the AskURL sub, which works.
 
Last edited:

JohnC

Well-Known Member
Licensed User
Fortunately, my routine always returns a True for the wv_OverrideURL event, telling the wv it should not process the click any further, so my workaround solved this particular situation.

But if MsgBox's can't be used in events such as this, then how would I be able to ask a user to make a choice when this event is triggered, and selectively return a true or false based on that choice?
 

Erel

Administrator
Staff member
Licensed User
But if MsgBox's can't be used in events such as this, then how would I be able to ask a user to make a choice when this event is triggered, and selectively return a true or false based on that choice?
Apparently it is not possible to pause the process at that point. A possible solution:
B4X:
Sub wv_OverrideUrl(url As String) As Boolean
 AskUser(url)
 Return True
End Sub

Sub AskUrl(url As String)
Msgbox2Async("Load page?", "Title", "Yes", "Cancel", "No", Null, False)
   Wait For Msgbox_Result (Result As Int)
   If Result = DialogResponse.POSITIVE Then
    wv.LoadUrl(url)
   End If
End Sub
 

JohnC

Well-Known Member
Licensed User
Its strange because if I instead use MsgBox (not MsgBox2), it will still pauses the process, but doesn't cause the instability issue that MsgBox2 does. Weird.

Learn something new everyday.
 
Top