Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Progress Dialog causing LoginActivity to be leaked #3

Open
@AmandaRiu

Description

@AmandaRiu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions