隐藏自定义对话框时窗口被泄露

时间:2016-08-26 05:41:42

标签: android

我使用以下代码创建自定义对话框。

private void alertLoginSuccess() {
        customDialog.loadigText.setText("Login Successful...");
        Glide.with(getApplicationContext())
                .load(R.drawable.tick)
                .into(customDialog.loadigIcon);
        final Handler handler  = new Handler();
        final Runnable runnable = new Runnable() {
            @Override
            public void run() {
                if (customDialog.isShowing()) {
                    customDialog.hide();
                }
                moveToDashboard(session_token);
            }
        };
        handler.postDelayed(runnable, 1000);
    }

当用户成功登录后,将出现登录成功对话框,然后将其移至仪表板。

但我得到以下错误,

  

android.view.WindowLeaked:活动com.know.LoginActivity已泄露   window com.android.internal.policy.impl.PhoneWindow $ DecorView {41ef86e0   G.E ..... R .....我。 0,0-169,59}最初是在这里添加的                                                                           在android.view.ViewRootImpl。(ViewRootImpl.java:388)                                                                           在   android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)                                                                           在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)                                                                           在android.app.Dialog.show(Dialog.java:286)

我怎样才能解决这个问题?

1 个答案:

答案 0 :(得分:3)

替换

customDialog.hide();

customDialog.dismiss();

因为当您移动到其他屏幕时,hide()会导致泄露的窗口错误。