由于进度对话框,我正在泄露窗口。在完成页面加载后,已经尝试了progress.dismiss(给定答案之一)。无法弄清楚崩溃的原因:/ 如果您有任何想法,请分享。
public class Webview3 extends Activity {
private WebView webView;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.activity_webview2);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new MyWebViewClient());
webView.setBackgroundResource(R.drawable.test1);
webView.setBackgroundColor(0x00000000);
progressDialog = new ProgressDialog(Webview3.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
String url = "http://www.matrimonyphotography.com/testimonial.shtml";
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setBuiltInZoomControls(false);
if (Build.VERSION.SDK_INT >= 19) {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
else {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
webView.loadUrl(url);
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
}
这是我的错误日志,它告诉问题的区域是progressDialog.show();和progressDialog.dismiss();在onFinishedPage()
05-10 18:48:37.044 3470-3470/com.evolved.ayshir.picdrift E/WindowManager: android.view.WindowLeaked: Activity com.evolved.ayshir.picdrift.Webview has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{268317b8 V.E..... R.....ID 0,0-1026,348} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:271)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:298)
at com.evolved.ayshir.picdrift.Webview.onCreate(Webview.java:40)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
05-10 18:48:40.271 3470-3470/com.evolved.ayshir.picdrift E/AndroidRuntime: java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{268317b8 V.E..... R.....ID 0,0-1026,348} not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:396)
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:322)
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:116)
at android.app.Dialog.dismissDialog(Dialog.java:341)
at android.app.Dialog.dismiss(Dialog.java:324)
at com.evolved.ayshir.picdrift.Webview$MyWebViewClient.onPageFinished(Webview.java:113)
at com.android.webview.chromium.WebViewContentsClientAdapter.onPageFinished(WebViewContentsClientAdapter.java:524)
at org.chromium.android_webview.AwContentsClientCallbackHelper$MyHandler.handleMessage(AwContentsClientCallbackHelper.java:188)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
答案 0 :(得分:1)
我有一些类似的问题。我发现在某些情况下,即使显示对话框,布尔值isShowing也会返回false。 尝试检查它是否为空,并在其上调用dismiss。这对我有用。
答案 1 :(得分:0)
首次初始化
progressDialog = new ProgressDialog(Webview3.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
然后输入以下代码
webView.setWebViewClient(new MyWebViewClient());
webView.setBackgroundResource(R.drawable.test1);
webView.setBackgroundColor(0x00000000);