Ad

Android WebView - First Click / Touch Is Ignored After Activity Started

We are building an hybrid Razor HTML5/Xamarin Android application. The rendering of the views in an Android.Webkit.WebView itself works pretty well and we got many forms designed properly, but we got a problem with the performance of the javascript execution in the single views.

I'll try to describe what's happening. We call the webview, generate the razor html template with the view specific model. After that we call the view with "LoadDataWithBaseUrl" which works. The view gets loaded by the webview control. Now I'll try to use buttons which are implemented in the view. The onclick handlers of the buttons are implemented in the views header section script tag in javascript. Example implementation:

...
function ClearInput() {
    var input = document.getElementById('page-text-input');
    input.value = "";
}
...
<input type="button" class="numeric-input-function" onclick="ClearInput();"/>

The problem that occurs is that we aren't able to use the button directly after the view has been rendered by the webview control. It seems like the javascript isn't directly available. There is no click event thrown for the first button click in the process. The second click and following ones work.

As a result of this misbehavior we have restricted usability. To clarify: The user sees the view but isn't able to operate properly because the click event for the first click isn't recognized.

Does anybody else have the same kind of issue or a solution for that problem?

Edit: We tried to disable the forms with a loading screen while it isn't fully loaded but that wasn't the solution were looking for. The problem still remains. It seems like the webview isn't focused on start and the first click is needed to setup the focus.

Edit 2: I made some more tests and recognized that the input channel is destroyed right after its constructed everytime I call the webview. The corresponding debug output looks as follows:

08-16 16:50:01.583 D/InputTransport(31313): Input channel constructed: fd=144
08-16 16:50:01.583 D/InputTransport(31313): Input channel destroyed: fd=132
08-16 16:50:03.813 D/Mono    (31313): GC_BRIDGE waiting for bridge processing to finish
08-16 16:50:03.856 I/art     (31313): Starting a blocking GC Explicit
08-16 16:50:03.894 I/art     (31313): Explicit concurrent mark sweep GC freed 18081(2MB) AllocSpace objects, 87(4MB) LOS objects, 14% free, 91MB/107MB, paused 559us total 38.349ms
08-16 16:50:03.927 D/Mono    (31313): GC_TAR_BRIDGE bridges 6498 objects 8686 opaque 242 colors 6492 colors-bridged 6479 colors-visible 6479 xref 101 cache-hit 0 cache-semihit 0 cache-miss 13 setup 0.72ms tarjan 7.96ms scc-setup 2.09ms gather-xref 0.36ms xref-setup 0.07ms cleanup 0.76ms
08-16 16:50:03.927 D/Mono    (31313): GC_BRIDGE: Complete, was running for 114.00ms
08-16 16:50:03.927 D/Mono    (31313): GC_MAJOR: (LOS overflow) time 102.71ms, stw 104.75ms los size: 27552K in use: 23334K
08-16 16:50:03.927 D/Mono    (31313): GC_MAJOR_SWEEP: major size: 10240K in use: 8427K
08-16 16:50:07.126 D/[email protected][CoordinatorActivity](31313): Relayout returned: oldFrame=[0,0][2048,1536] newFrame=[0,0][2048,1536] result=0x1 surface={isValid=true -913786880} surfaceGenerationChanged=false
08-16 16:50:08.112 D/[email protected][CoordinatorActivity](31313): ViewPostImeInputStage processPointer 0
08-16 16:50:08.215 D/[email protected][CoordinatorActivity](31313): ViewPostImeInputStage processPointer 1
08-16 16:50:08.732 D/[email protected][CoordinatorActivity](31313): ViewPostImeInputStage processPointer 0
08-16 16:50:08.800 D/[email protected][CoordinatorActivity](31313): ViewPostImeInputStage processPointer 1
08-16 16:50:08.818 D/InputMethodManager(31313): HSI from window - flag : 0 Pid : 31313
08-16 16:50:08.824 D/InputMethodManager(31313): HSI from window - flag : 0 Pid : 31313
08-16 16:50:08.828 D/InputMethodManager(31313): HSI from window - flag : 0 Pid : 31313
08-16 16:50:08.831 D/InputMethodManager(31313): HSI from window - flag : 0 Pid : 31313

Edit 3: I tried different flags, settings for focusable and focusableInTouchMode and ontouch / onfocuschanged event handlers but nothing seems to work. Nobody got an idea about how to fix that problem?

Ad

Answer

I've found the solution. The reason was that "system_ui_flag_hide_navigation" was set. I don't know why that side effect occured, but after I removed the line, it worked. Just in case somebody else also runs into that problem.

Ad
source: stackoverflow.com
Ad