我写了以下代码来使用webview生成位图,在Android Lolipop中,我得到了以下异常webView.draw(canvas);
,它在5.0版本以外可以正常工作:
代码:
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;
}
异常:
java.lang.RuntimeException: Probable deadlock detected due to WebView API being called on incorrect thread while the UI thread is blocked.
我该如何修复这个问题?