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 4125882
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:55:39+00:00 2026-05-20T23:55:39+00:00

I have webview, and I’m using geo-location feature in android. I’m using javascript (onload)

  • 0

I have webview, and I’m using geo-location feature in android.
I’m using javascript (onload) to call Android method

public void getLocation() {
   _context.getLocation();
}

and when location recieved this execute

public void locationUpdated(Location location) {
        NumberFormat frm = NumberFormat.getNumberInstance(new Locale("en_US"));
        // call javascript function
        webView.loadUrl("javascript:locationChangedHandler(" + frm.format (location.getLatitude()) + "," + frm.format(location.getLongitude()) + ")");
}

Sometime I got this exception, and this exception

04-04 01:17:06.262: ERROR/AndroidRuntime(659): FATAL EXCEPTION: Timer-1
        android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
        at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
        at android.view.ViewRoot.invalidateChild(ViewRoot.java:607)
        at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:633)
        at android.view.ViewGroup.invalidateChild(ViewGroup.java:2505)
        at android.view.View.invalidate(View.java:5139)
        at android.view.View.onFocusChanged(View.java:2664)
        at android.widget.TextView.onFocusChanged(TextView.java:6469)
        at android.widget.AutoCompleteTextView.onFocusChanged(AutoCompleteTextView.java:1048)
        at android.webkit.WebTextView.onFocusChanged(WebTextView.java:357)
        at android.view.View.clearFocusForRemoval(View.java:2577)
        at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2188)
        at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2181)
        at android.view.ViewGroup.removeView(ViewGroup.java:2129)
        at android.webkit.WebTextView.remove(WebTextView.java:583)
        at android.webkit.WebView.clearTextEntry(WebView.java:1830)
        at android.webkit.WebView.loadUrl(WebView.java:1542)
        at android.webkit.WebView.loadUrl(WebView.java:1553)
        at com.binus.MainView$1.gotLocation(MainView.java:33)
        at com.binus.GeoLocation$GetLastLocation.run(GeoLocation.java:88)
        at java.util.Timer$TimerImpl.run(Timer.java:289)

Is this something todo with accessing UI thread from other thread ?
Is calling Android (Java) method from Javascript execute on non UI thread ?

And how to make my code thread safe ?

  • 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-05-20T23:55:39+00:00Added an answer on May 20, 2026 at 11:55 pm

    I’m not sure how you got off the UI thread, but to get back on you can use post:

    public void locationUpdated(final Location location) {
        post(new Runnable() {
            @Override
            public void run() {
                webView.loadUrl(...);
            }
        });
    }
    

    if you’re inside a View. If you’re in an Activity then change post to runOnUiThread.

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

Sidebar

Related Questions

I have a WebView that I'm using to open some files stored in the
I have a WebView and the it loads a html page which has javascript
I have an Android app that uses a WebView to enable users to install
I've got an issue with WebView on Android 3.1 and higher. I have a
I have WebView which loads some page, when it's finished I apply some javascript
What I want to do... I have a webview in my android app. I
I have a WebView in my activity, and using Proguard for obfuscation seems to
I have a webview with javascript-interface. From within this webview i do certain javascript
I have a WebView with data populated from local javascript (in the asset folder).
I have a WebView at the bottom of view in ViewPager ... When I

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.