Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7723129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:21:57+00:00 2026-06-01T04:21:57+00:00

In a WebView-derived class I override loadUrl(): @Override public void loadUrl(String url) { super.loadUrl(url);

  • 0

In a WebView-derived class I override loadUrl():

  @Override
  public void loadUrl(String url) {
    super.loadUrl(url);
  }  

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.).

I was initially thinking of distinguishing between the two by setting a flag in an OnTouchListener():

public boolean onTouch(View v, MotionEvent event) {
  if (event.getAction() == MotionEvent.ACTION_UP) {
      // set flag !!!
  }
  return false;
} 

and resetting it in loadUrl(), after checking its value.

The problem with this “solution” is that in the aforementioned onTouch() implementation, any touch sets the flag, so a false scenario like this is possible:

  1. The user touches the screen (but not a link!)
  2. onTouch sets the flag.
  3. My program calls loadUrl() directly.
  4. loadUrl() checks the flag and thinks that it was called as result of a touch.

So obviously the above onTouch() handling is too simplistic and doesn’t work.

Any idea how to implement code that actually knows how to tell between a touch-triggered loadUrl() and a non-touch-triggered loadUrl()?

Update: I checked the stack trace suggestion below, and this is the stack trace at loadUrl() when it is invoked via touch:

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)

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):

android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:216)
android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:323)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:21:59+00:00Added an answer on June 1, 2026 at 4:21 am

    I don’t know of a proper way to do what you’re asking but I can think of a way that will probably work. In your loadUrl() override, you can query your calling stack and see what routine called into you. Your caller will be one location for a touch leading to you, and anything else for having been called programatically.

    http://www.javapractices.com/topic/TopicAction.do?Id=78 contains code showing how to determine your stack trace from a throwable (which you would create in your loadUrl() method).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i try a simple webView appication. and this is my code : public void
private WebView wv; public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.infoweblinkview); wv=(WebView) findViewById(R.id.weblinkview); wv.setWebViewClient(new WebViewClient());
I have simple WebView code like this: WebView wv = (WebView) findViewById(R.id.webview1); wv.loadUrl(http://en.wikipedia.org/wiki/Book); But
I manage to display a webview with the content that being derived from string,
I have a webview and want to drag the url on the webview to
I have a webview and I want to manually switch to another tab during
I have a webview, which shows the pages of a ebook. I want to
I'm working with a WebView. If I place this call in my -awakeFromNib :
I am loading a WebView to the LinearLayout and want to display a ProgressBar
webview = (WebView) findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl(http://officeofthemufti.sg/MaulidBooklet.pdf); I am using WebView try to loading pdf

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.