Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to tell if loadUrl() was called DIRECTLY or as a result of touching a link?
    primarykey
    data
    text
    <p>In a WebView-derived class I override loadUrl():</p> <pre><code> @Override public void loadUrl(String url) { super.loadUrl(url); } </code></pre> <p>Inside this overriden loadUrl(), I want to know whether it was called as a result of the user touching a link (inside the same WebView), or was actually called directly somewhere in my program (either directly by me, or indirectly as a result of some Javascript processing etc.).</p> <p>I was initially thinking of distinguishing between the two by setting a flag in an <code>OnTouchListener()</code>:</p> <pre><code>public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { // set flag !!! } return false; } </code></pre> <p>and resetting it in loadUrl(), <em>after</em> checking its value.</p> <p>The problem with this "solution" is that in the aforementioned onTouch() implementation, <em>any</em> touch sets the flag, so a false scenario like this is possible:</p> <ol> <li>The user touches the screen (but not a link!)</li> <li>onTouch sets the flag.</li> <li>My program calls loadUrl() directly.</li> <li>loadUrl() checks the flag and thinks that it was called as result of a touch.</li> </ol> <p>So obviously the above onTouch() handling is too simplistic and doesn't work.</p> <p>Any idea how to implement code that actually knows how to tell between a touch-triggered loadUrl() and a <strong>non</strong>-touch-triggered loadUrl()?</p> <p><strong>Update:</strong> I checked the stack trace suggestion below, and this is the stack trace at loadUrl() when it is invoked via touch:</p> <pre><code>com.utubefan.MyWebView.loadUrl(MyWebView.java:365) com.utubefan.MyWebViewClient.shouldOverrideUrlLoading(MyWebViewClient.java:123) android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:216) android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:323) android.os.Handler.dispatchMessage(Handler.java:99) android.os.Looper.loop(Looper.java:123) android.app.ActivityThread.main(ActivityThread.java:4627) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:521) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) dalvik.system.NativeStart.main(Native Method) </code></pre> <p>I am not sure that I can identify an explicit touch event there, but the following looks promising (they don't appear on a non-touch loadUrl):</p> <pre><code>android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:216) android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:323) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload