Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress Dialog causing LoginActivity to be leaked #3

Open
AmandaRiu opened this issue Jun 1, 2018 · 0 comments
Open

Progress Dialog causing LoginActivity to be leaked #3

AmandaRiu opened this issue Jun 1, 2018 · 0 comments

Comments

@AmandaRiu
Copy link
Contributor

The Issue
The LoginActivity is being leaked if the progress dialog is visible during a configuration change. Here is the stacktrace that is thrown:

WindowManager  E  android.view.WindowLeaked: Activity com.woocommerce.android.ui.login.LoginActivity has leaked window DecorView@a0f7aaf[] that was originally added here
             E      at android.view.ViewRootImpl.<init>(ViewRootImpl.java:485)
             E      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346)
             E      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
             E      at android.app.Dialog.show(Dialog.java:330)
             E      at android.app.ProgressDialog.show(ProgressDialog.java:185)
             E      at org.wordpress.android.login.LoginBaseFormFragment.startProgress(LoginBaseFormFragment.java:219)
             E      at org.wordpress.android.login.LoginEmailPasswordFragment.next(LoginEmailPasswordFragment.java:213)
             E      at org.wordpress.android.login.LoginEmailPasswordFragment$2.onClick(LoginEmailPasswordFragment.java:164)
             E      at android.view.View.performClick(View.java:6294)
             E      at android.view.View$PerformClick.run(View.java:24770)
             E      at android.os.Handler.handleCallback(Handler.java:790)
             E      at android.os.Handler.dispatchMessage(Handler.java:99)
             E      at android.os.Looper.loop(Looper.java:164)
             E      at android.app.ActivityThread.main(ActivityThread.java:6494)
             E      at java.lang.reflect.Method.invoke(Native Method)
             E      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
             E      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Steps to Reproduce

  1. Install a fresh version of the app (or logout)
  2. Login with email, then enter password and hit next - the progress dialog will show
  3. Immediately change the orientation of the device
  4. Observe error in the logs

Recommended Fix
Dismiss the dialog and drop the reference, for example in LoginBaseFormFragment:

    @Override public void onDestroyView() {
        if (mProgressDialog != null) {
            mProgressDialog.dismiss();
            mProgressDialog = null;
        }
        super.onDestroyView();
    }

Note: I recommend using mProgressDialog.dismiss() instead of mProgressDialog.cancel() to avoid doing unnecessary work defined in the OnCancelListener.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant