我有一个我试图杀死的 webview,但它是一个硬混蛋!我试过了:
在我的活动中:
@Override
protected void onStop() {
if (webView_ != null) {
webView_.finish(getApplicationContext());
webView_.destroy();
webView_ = null;
}
super.onStop();
}
在我的网络视图中:
public void finish(Context context) {
stopLoading();
pauseTimers();
if (alarm_ != null)
alarm_.cancelAlarm(context);
if (webViewErrorHandler_ != null)
webViewErrorHandler_.removeCallbacks(reloadRunnable_);
if (requestQueue_ != null) {
requestQueue_.clear();
requestQueue_ = null;
}
callHiddenWebViewMethod("onPause");
}
private void callHiddenWebViewMethod(String name){
if( this != null ){
try {
Method method = WebView.class.getMethod(name);
method.invoke(this);
} catch (NoSuchMethodException e) {
Log.e("MYWEBVIEW", "No such method: " + name);
} catch (IllegalAccessException e) {
Log.e("MYWEBVIEW", "Illegal Access: " + name);
} catch (InvocationTargetException e) {
Log.e("MYWEBVIEW", "Invocation Target Exception: " + name);
}
}
}
但是当我在调试器中查看它时,仍然有这个 webview 的线程在运行!
而且你必须知道我特别希望它在 onPause 之后工作;)