Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeException creating a WebView dynamically in Android O

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?

like image 950
Cigogne Eveillée Avatar asked Oct 29 '22 16:10

Cigogne Eveillée


1 Answers

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.

like image 125
Cigogne Eveillée Avatar answered Nov 08 '22 09:11

Cigogne Eveillée