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

Commit 35e17456 authored by Jay Shrauner's avatar Jay Shrauner
Browse files

Fix IllegalStateException in onBackPressed

Check to make sure the activity is still visible before doing anything.

Bug:24130014
Change-Id: I4d732902a78bf30468a25c46c0f17d71bc84aefd
parent e11e06ac
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ public class ContactSelectionActivity extends ContactsActivity
    private ContactsIntentResolver mIntentResolver;
    protected ContactEntryListFragment<?> mListFragment;

    private boolean mIsVisible;

    private int mActionCode = -1;
    private boolean mIsSearchMode;
    private boolean mIsSearchSupported;
@@ -137,6 +139,25 @@ public class ContactSelectionActivity extends ContactsActivity
        prepareSearchViewAndActionBar();
    }

    @Override
    protected void onStart() {
        super.onStart();
        mIsVisible = true;
    }

    @Override
    protected void onStop() {
        mIsVisible = false;
        super.onStop();
    }

    /**
     * Returns true when the Activity is currently visible (between onStart and onStop).
     */
    /* package */ boolean isVisible() {
        return mIsVisible;
    }

    private void prepareSearchViewAndActionBar() {
        final ActionBar actionBar = getActionBar();
        mSearchViewContainer = LayoutInflater.from(actionBar.getThemedContext())
@@ -212,6 +233,7 @@ public class ContactSelectionActivity extends ContactsActivity

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        mIsVisible = false;
        super.onSaveInstanceState(outState);
        outState.putInt(KEY_ACTION_CODE, mActionCode);
        outState.putBoolean(KEY_SEARCH_MODE, mIsSearchMode);
@@ -672,6 +694,10 @@ public class ContactSelectionActivity extends ContactsActivity

    @Override
    public void onBackPressed() {
        if (!isVisible()) {
            return;
        }

        if (mIsSearchMode) {
            mIsSearchMode = false;
            configureSearchMode();