I figured this out - I violated the "The task instance must be created on the UI thread" rule stated in the Reference.
On Sep 22, 8:47 pm, Miguel Paraz <mpa...@gmail.com> wrote: > On Sep 21, 6:11 pm, "Mark Murphy" <mmur...@commonsware.com> wrote: > > > > I made an example that sleeps inside the Runnable. The entire WebView > > > becomes unresponsive! What is the proper way (if any) of implementing > > > a long-running JavaScript call? > > > Everything is fine except for sleeping in the Runnable. The Runnable is > > run on the UI thread -- sleeping on the UI thread, like sleeping on the > > job, is not a good idea. > > > If you want something that will run for a long time, use a background > > thread, perhaps in the form of an AsyncTask. > > Thanks for the tip. I forgot that the Handler executes Runnables on > the UI thread. I thought instead that it was like an Executor. > > > > Is it safe to call loadUrl() from multiple threads? > > > I have not tried it, but I doubt it. If you use AsyncTask, do your > > loadUrl() in onPostExecute(). > > I found that loadUrl() is not safe to be called using AsyncTask. > onPostExecute() is not called by the "main" thread, but by > "WebViewCoreThread". > This breaks if a text box is in use, which needs to run in "main." > > The solution is to manually use a Handler. > > 09-22 20:01:19.943: ERROR/AndroidRuntime(768): Uncaught handler: > thread WebViewCoreThread exiting due to uncaught exception > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): android.view.ViewRoot > $CalledFromWrongThreadException: Only the original thread that created > a view hierarchy can touch its views. > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.view.ViewRoot.checkThread(ViewRoot.java:2440) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.view.ViewRoot.invalidateChild(ViewRoot.java:522) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:540) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.view.ViewGroup.invalidateChild(ViewGroup.java:2332) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.view.View.invalidate(View.java:4437) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.view.View.onFocusChanged(View.java:2428) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.widget.TextView.onFocusChanged(TextView.java:6211) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.widget.AutoCompleteTextView.onFocusChanged > (AutoCompleteTextView.java:767) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.view.View.clearFocusForRemoval(View.java:2346) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.view.ViewGroup.removeViewInternal(ViewGroup.java:2034) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.view.ViewGroup.removeViewInternal(ViewGroup.java:2027) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.view.ViewGroup.removeView(ViewGroup.java:1975) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.webkit.TextDialog.remove(TextDialog.java:395) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.webkit.WebView.clearTextEntry(WebView.java:1374) > 09-22 20:01:20.113: ERROR/AndroidRuntime(768): at > android.webkit.WebView.loadUrl(WebView.java:1116) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---