Reputation: 31
I write the following code to generate the bitmap using webview and I got the following exception webView.draw(canvas);
in Android Lolipop, it's working except the 5.0:
Code:
protected Bitmap doInBackground(Void... params) {
try {
Bitmap bitmap = null;
Thread.sleep(5000);
if (webView.getMeasuredHeight() > 0) {
bitmap = Bitmap.createBitmap(webView.getMeasuredWidth(),
webView.getMeasuredHeight(), Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
webView.draw(canvas);
return bitmap;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Exception:
java.lang.RuntimeException: Probable deadlock detected due to WebView API being called on incorrect thread while the UI thread is blocked.
How can I fix this?
Upvotes: 3
Views: 501
Reputation: 6866
This exception is thrown from WebViewChromium.runBlockingFuture().
There, some task (in your case, probably the drawing) is put on a queue to run on the UI thread.
Then, we wait for the result for up to four seconds. If the task hasn't completed by that time, you'll get that exception.
I see two possible reasons for taking that long:
I think #2 is more likely. You should check what your main thread is doing at this point. Are there any potential mutex issues, like a deadlock? Or maybe it's just very busy?
Upvotes: 1