webview加载页面为什么在UI线程里面做,难道不是耗时操作么

2026年09月23日 19:11
有1个网友回答
网友(1):

WebView 里面必须放在UI线程里面展示。
private static void checkThread() {
if (Looper.myLooper() != Looper.getMainLooper()) {
Throwable throwable = new Throwable(
"Warning: A WebView method was called on thread '" +
Thread.currentThread().getName() + "'. " +
"All WebView methods must be called on the UI thread. " +
"Future versions of WebView may not support use on other threads.");
Log.w(LOGTAG, Log.getStackTraceString(throwable));
StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
}
}

加载URL是用的底层回调方法,应该用的是Webkit内核。
每个WebView实例关联一个 WebViewProvider 来处理数据加载,这个加载是异步的,经常发现WebView显示了,发现内容还未显示。