From c2fbff362cff30cf547248240e4e4cf2ae8a3c7d Mon Sep 17 00:00:00 2001 From: Jay Shrauner Date: Thu, 24 Sep 2015 12:02:04 -0700 Subject: Fix IllegalStateException in onOptionsItemSelected Check to make sure the activity is still visible before doing anything. Bug:24373052 Change-Id: I35a05227f02c117b29b5a29af9dfc54c00ba3616 --- .../dialer/settings/DialerSettingsActivity.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src') diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java index 2b7277224..fee0fa88e 100644 --- a/src/com/android/dialer/settings/DialerSettingsActivity.java +++ b/src/com/android/dialer/settings/DialerSettingsActivity.java @@ -35,12 +35,39 @@ import java.util.List; public class DialerSettingsActivity extends AppCompatPreferenceActivity { protected SharedPreferences mPreferences; + private boolean mIsVisible; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPreferences = PreferenceManager.getDefaultSharedPreferences(this); } + @Override + protected void onStart() { + super.onStart(); + mIsVisible = true; + } + + @Override + protected void onStop() { + mIsVisible = false; + super.onStop(); + } + + @Override + protected void onSaveInstanceState(Bundle out) { + mIsVisible = false; + super.onSaveInstanceState(out); + } + + /** + * Returns true when the Activity is currently visible (between onStart and onStop). + */ + /* package */ boolean isVisible() { + return mIsVisible; + } + @Override public void onBuildHeaders(List
target) { Header displayOptionsHeader = new Header(); @@ -130,6 +157,14 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { return false; } + @Override + public void onBackPressed() { + if (!isVisible()) { + return; + } + super.onBackPressed(); + } + @Override protected boolean isValidFragment(String fragmentName) { return true; -- cgit v1.2.3