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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:15:50+00:00 2026-06-16T02:15:50+00:00

My app is a hybrid html5 + JS + android which run in webview

  • 0

My app is a hybrid html5 + JS + android which run in webview and communicate so much with Andorid through JS interface.

I got some report that it fails after 2 second on some devices. I added ACRA so I can get reports, but I didn’t get any thing.

So I tried to test it myself, To raise an exception I add a code that manipulate views of main thread in Javascript interface’s function which was triggered with a button in html. This raise an exception: Only the original thread that created a view hierarchy can touch its views. Now the app start and when I tap the button it exit with exception and ACRA send the report.

Then I put the manipulation code in a function of JS interface which was called immediately after the app start. now app is closed after a second. But ACRA doesn’t send any error. Even an ExceptionHandler didn’t catch it but catch the first case.

This is the log of second scenario:

59): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@43f8d990 (uid=10019 pid=329)
12-15 01:18:07.047: WARN/dalvikvm(409): JNI WARNING: JNI method called with exception raised
12-15 01:18:07.047: WARN/dalvikvm(409): in Landroid/webkit/BrowserFrame;.stringByEvaluatingJavaScriptFromString (Ljava/lang/String;)Ljava/lang/String; (NewString)
12-15 01:18:07.057: WARN/dalvikvm(409): Pending exception is:
12-15 01:18:07.057: INFO/dalvikvm(409): Landroid/view/ViewRoot$CalledFromWrongThreadException;: Only the original thread that created a view hierarchy can touch its views

I don’t know what this pending exception is? I couldn’t find anything on web. I wonder why dont ACRA or Exception Handler catch it?

class JavaScriptInterface
{
    MyActivity parent;
    JavaScriptInterface(MyActivity parent)
    {
        this.parent = parent;
    }

    public void immediatelyCalled() 
    // Webview load index.html in oncreate of activity and js inside html calls this function immediately
    {
        parent.textview1.setText("test"); 
        // raise an exception which ACRA or Exception Handler dont catch
        // Problem is here
    }

    public void buttonCalled() 
    // This is called when a button is tapped in html
    {
        parent.textview1.setText("test"); 
        // raise an exception which Exception Handler and ACRA catch
    }
}

this is my activity:

public class MyActivity extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
setContentView(R.layout.main);

        class MyExceptionHandler implements Thread.UncaughtExceptionHandler
        {
            @Override
            public void uncaughtException(Thread thread, Throwable throwable)
            {
                Log.d("ExceptionHandler", "Caught exception: " + throwable.getClass().getName() + ": " + throwable.getMessage());
            }
        }

        MyExceptionHandler handler = new MyExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(handler);


        this.wv = (WebView) findViewById(R.id.webview);
        this.wv.addJavascriptInterface(new JavaScriptInterface(this), "android");
        this.ws = this.wv.getSettings();
        this.ws.setJavaScriptEnabled(true);
        this.wv.loadUrl("file:///android_asset/index.html");

    }
}

this is part of index.html:

<script type="text/javascript">
android.immediatelyCalled();
</scritp>
<button onclick="android.buttonCalled()"></button>

Tested on AVD 2.2 and Xperai Arc 4.0.3, Both the same

  • 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-16T02:15:51+00:00Added an answer on June 16, 2026 at 2:15 am

    I think the method immediatelyCalled() is called in another thread than the one you are creating “MyActivity parent” (a UI thread, your apps main thread). So an uncaught exception handler which you assign to the ui thread and which has nothing to do with the process which is running the javascript code, can not catch this exception occuring at setText (accessing a view which belongs to another thread).

    I think you could catch the exception of course if you enclose parent.textview1.setText(“test”); in a try catch block.
    You should be able to avoid the exception if you modify the setText call in this way:

    parent.textView1.post(new Runnable() {
        public void run() {
            parent.textview1.setText("test");
        }
    });
    

    You’ll have to mark your parent parameter as final.
    Unfortunately i have no eclipse here to test and it’s late already 🙂
    good luck!

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

Sidebar

Related Questions

I just started make a kind of Android hybrid app, an application with WebView.
When we are building html5 web app or ios hybrid app,we need to make
I'm building an hybrid Android App using Phonegap/Apache Cordova. My app should get data
I'm trying to develop a Hybrid android app where all by logic to get
I am currently creating a hybrid mobile app (see phonegap/cordova) for iOS and Android
i'm developing hybrid app using JQM + PhoneGap on Android. when i change the
I have a hybrid mobile app built on Trigger.io that opens links (some of
I want to build a hybrid app can run on all devices. I use
In my hybrid Android application, on a ListView item click I'm loading a WebView
I have a MyThread object which I instantiate when my app is loaded through

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.