Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit feec1985 authored by James Lemieux's avatar James Lemieux
Browse files

Fix DeskClock recreation after altering settings

Bug: 25121359

Calling Activity.recreate() while the activity is paused will create
a new copy of the activity that remains paused, even if it is the
foreground activity.

To work around this, we delay recreating the activity until after
it identifies as being resumed. This produces a noticeable flash
but is far better than the alternative...

Change-Id: Iae770a25fb5b6f80d50a321a0f2f4cd792eceb10
parent cbb9333b
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -86,6 +86,9 @@ public class DeskClock extends BaseActivity
    private TabsAdapter mTabsAdapter;
    private int mSelectedTab;

    /** {@code true} when a settings change necessitates recreating this activity. */
    private boolean mRecreateActivity;

    @Override
    public void onNewIntent(Intent newIntent) {
        super.onNewIntent(newIntent);
@@ -211,6 +214,24 @@ public class DeskClock extends BaseActivity
        DataModel.getDataModel().setApplicationInForeground(true);
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();

        if (mRecreateActivity) {
            mRecreateActivity = false;

            // A runnable must be posted here or the new DeskClock activity will be recreated in a
            // paused state, even though it is the foreground activity.
            mViewPager.post(new Runnable() {
                @Override
                public void run() {
                    recreate();
                }
            });
        }
    }

    @Override
    public void onPause() {
        DataModel.getDataModel().setApplicationInForeground(false);
@@ -249,7 +270,7 @@ public class DeskClock extends BaseActivity
        // Recreate the activity if any settings have been changed
        if (requestCode == SettingMenuItemController.REQUEST_CHANGE_SETTINGS
                && resultCode == RESULT_OK) {
            recreate();
            mRecreateActivity = true;
        }
    }