6

I'm creating a Webview dynamically from an IntentService in Android O, and getting the following crash:

java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:353) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383) at java.util.concurrent.FutureTask.setException(FutureTask.java:252) at java.util.concurrent.FutureTask.run(FutureTask.java:271) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.RuntimeException: Did not yet override the UI thread at org.chromium.base.ThreadUtils.getUiThreadHandler(ThreadUtils.java:5) at org.chromium.base.ThreadUtils.runningOnUiThread(ThreadUtils.java:45) at com.android.webview.chromium.WebViewChromiumFactoryProvider.C(WebViewChromiumFactoryProvider.java:149) at com.android.webview.chromium.WebViewChromiumFactoryProvider.l(WebViewChromiumFactoryProvider.java:262) at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:29) at android.webkit.WebView.<init>(WebView.java:658) at android.webkit.WebView.<init>(WebView.java:588) at android.webkit.WebView.<init>(WebView.java:571) at android.webkit.WebView.<init>(WebView.java:558) at android.webkit.WebView.<init>(WebView.java:548)

This used to work fine with earlier versions of Android. Any ideas?

Cigogne Eveillée
  • 2,178
  • 22
  • 36
  • As the message indicates there is some problem with a class that is interacting with the UI thread. I have seen similar problems in the past and worked around them by doing all WebView interactions on the UI thread. In your service, can you try the following: `context.runOnUiThread(new Runnable() {public void run() { /* your code here */ }});` (replace /*your code here*/ with the code that creates the WebView.) ` – EJK Mar 20 '18 at 01:37
  • Unfortunately `runOnUiThread` is a method of `Activity` not `Context`, which is not relevant in the context of a service. – Cigogne Eveillée Mar 20 '18 at 05:25
  • see https://stackoverflow.com/questions/18948251/not-able-to-call-runonuithread-in-a-thread-from-inside-of-a-service – EJK Mar 20 '18 at 07:39

1 Answers1

2

As @EJK mentioned, the solution was to run the problematic code on the UI thread. I achieved that by switching from an IntentService to a Service.

Cigogne Eveillée
  • 2,178
  • 22
  • 36