应用程序在解除ProgressBar时崩溃

时间:2016-02-26 14:44:37

标签: java android mobile

我们的应用程序在进度条上调用dismiss方法时崩溃了。我无法在我的设备中重现此崩溃,但这种情况发生在生产中。

public class SomeActivity extends BaseActivity {

    public SomeActivity() {
        super(true);
    }

    private WebView webView;
    private boolean hasRedirected = false;

    ProgressDialog loadingDialog;

    public void onCreate(Bundle savedInstanceState) {

        ...
        ...

        loadingDialog = new ProgressDialog(this);
        loadingDialog.setCancelable(true);
        loadingDialog.setMessage("Loading...");
        loadingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        loadingDialog.setIndeterminate(true);

        Intent intent = getIntent();
        String url = intent.getStringExtra(SomeActivity.urlToLoad);
        webView = (WebView) findViewById(R.id.webview);

        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSupportZoom(true);

        webView.loadUrl(url);

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished (WebView view, String url) {
                if (!url.equals("about:blank"))
                    loadingDialog.dismiss();
            }

            @Override
            public void onPageStarted (WebView view, String url, Bitmap favicon) {
                if (!url.equals("about:blank"))
                    loadingDialog.show();
            }

            ...
            ...

        });

    }

    ...
    ...

}

堆栈跟踪:

java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{1c03950b V.E..... R.....ID 0,0-1336,0} not attached to window manager
    at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:412)
    at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:338)
    at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:118)
    at android.app.Dialog.dismissDialog(Dialog.java:509)
    at android.app.Dialog.dismiss(Dialog.java:492)
    at com.xyz.activities.notification.SomeActivity$1.onPageFinished(SomeActivity.java:85)
    at com.android.webview.chromium.WebViewContentsClientAdapter.onPageFinished(WebViewContentsClientAdapter.java:513)
    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:145)
    at android.app.ActivityThread.main(ActivityThread.java:6895)
    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:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

1 个答案:

答案 0 :(得分:1)

请参阅Similar question,您将找到解决方案。