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

Commit 21b25771 authored by Chris Banes's avatar Chris Banes
Browse files

Fix ToolbarActionBar invalidating destroyed Activities

BUG: 26375399
Change-Id: Ieae13890896b1082b51a81317760b4975aeb5dff
parent 98edbe3e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1082,6 +1082,10 @@ public abstract class ActionBar {
        return false;
    }

    /** @hide */
    public void onDestroy() {
    }

    /**
     * Common implementation for requestFocus that takes in the Toolbar and moves focus
     * to the contents. This makes the ViewGroups containing the toolbar allow focus while it stays
+14 −2
Original line number Diff line number Diff line
@@ -1703,6 +1703,10 @@ public class Activity extends ContextThemeWrapper
            mSearchManager.stopSearch();
        }

        if (mActionBar != null) {
            mActionBar.onDestroy();
        }

        getApplication().dispatchActivityDestroyed(this);
    }

@@ -2208,14 +2212,22 @@ public class Activity extends ContextThemeWrapper
     * @param toolbar Toolbar to set as the Activity's action bar
     */
    public void setActionBar(@Nullable Toolbar toolbar) {
        if (getActionBar() instanceof WindowDecorActionBar) {
        final ActionBar ab = getActionBar();
        if (ab instanceof WindowDecorActionBar) {
            throw new IllegalStateException("This Activity already has an action bar supplied " +
                    "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " +
                    "android:windowActionBar to false in your theme to use a Toolbar instead.");
        }
        // Clear out the MenuInflater to make sure that it is valid for the new Action Bar

        // If we reach here then we're setting a new action bar
        // First clear out the MenuInflater to make sure that it is valid for the new Action Bar
        mMenuInflater = null;

        // If we have an action bar currently, destroy it
        if (ab != null) {
            ab.onDestroy();
        }

        ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this);
        mActionBar = tbab;
        mWindow.setCallback(tbab.getWrappedWindowCallback());
+6 −0
Original line number Diff line number Diff line
@@ -483,6 +483,12 @@ public class ToolbarActionBar extends ActionBar {
        return true;
    }

    @Override
    public void onDestroy() {
        // Remove any invalidation callbacks
        mDecorToolbar.getViewGroup().removeCallbacks(mMenuInvalidator);
    }

    public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
        mMenuVisibilityListeners.add(listener);
    }