diff options
author | Jay Shrauner <shrauner@google.com> | 2015-09-24 12:02:04 -0700 |
---|---|---|
committer | Jay Shrauner <shrauner@google.com> | 2015-09-24 12:06:25 -0700 |
commit | c2fbff362cff30cf547248240e4e4cf2ae8a3c7d (patch) | |
tree | 4b10cce60f02837c72f6dc8dd11af126ab1b2899 | |
parent | 1cc1b26c1e7205e5379f5180faeaedc0886b3760 (diff) |
Fix IllegalStateException in onOptionsItemSelected
Check to make sure the activity is still visible before doing anything.
Bug:24373052
Change-Id: I35a05227f02c117b29b5a29af9dfc54c00ba3616
-rw-r--r-- | src/com/android/dialer/settings/DialerSettingsActivity.java | 35 |
1 files changed, 35 insertions, 0 deletions
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,6 +35,8 @@ import java.util.List; public class DialerSettingsActivity extends AppCompatPreferenceActivity { protected SharedPreferences mPreferences; + private boolean mIsVisible; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -42,6 +44,31 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { } @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<Header> target) { Header displayOptionsHeader = new Header(); displayOptionsHeader.titleRes = R.string.display_options_title; @@ -131,6 +158,14 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { } @Override + public void onBackPressed() { + if (!isVisible()) { + return; + } + super.onBackPressed(); + } + + @Override protected boolean isValidFragment(String fragmentName) { return true; } |