2
votes

Im using the following code to create a custom dialog.

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);
    }

When the user has logged in successfully, the login successful dialog will appear and then they will be moved towards the dashboard.

But im getting the following error,

android.view.WindowLeaked: Activity com.know.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41ef86e0 G.E..... R.....I. 0,0-169,59} that was originally added here at android.view.ViewRootImpl.(ViewRootImpl.java:388) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) at android.app.Dialog.show(Dialog.java:286)

How can I be able to sort this out?

1
customDialog.dismiss()??kgandroid

1 Answers

2
votes

Replace

customDialog.hide();

with

customDialog.dismiss();

because hide() cause a leaked window error, while you are moving to other screen.