From f499a09cdbbd8efb4d97b9981fe1a0141e8a930d Mon Sep 17 00:00:00 2001 From: Jay Shrauner Date: Wed, 16 Sep 2015 15:49:56 -0700 Subject: Fix IllegalStateException in onOptionsItemSelected Make sure we're still visible before showing dialogs. Bug:24138858 Change-Id: I3a2cc7dba6144e055ae074177ba5c89258f69b1b --- .../android/dialer/calllog/CallLogActivity.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/com/android/dialer/calllog/CallLogActivity.java') diff --git a/src/com/android/dialer/calllog/CallLogActivity.java b/src/com/android/dialer/calllog/CallLogActivity.java index ff0726df7..ad795f9bd 100644 --- a/src/com/android/dialer/calllog/CallLogActivity.java +++ b/src/com/android/dialer/calllog/CallLogActivity.java @@ -48,6 +48,8 @@ public class CallLogActivity extends AppCompatActivity implements ViewPager.OnPa private CallLogFragment mAllCallsFragment; private CallLogFragment mMissedCallsFragment; + private boolean mIsVisible; + private String[] mTabTitles; private static final int TAB_INDEX_ALL = 0; @@ -160,6 +162,31 @@ public class CallLogActivity extends AppCompatActivity implements ViewPager.OnPa super.onPause(); } + @Override + protected void onStart() { + super.onStart(); + mIsVisible = false; + } + + @Override + protected void onStop() { + mIsVisible = false; + super.onStop(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + mIsVisible = false; + super.onSaveInstanceState(outState); + } + + /** + * Returns true when the Activity is currently visible (between onStart and onStop). + */ + /* package */ boolean isVisible() { + return mIsVisible; + } + @Override public boolean onCreateOptionsMenu(Menu menu) { final MenuInflater inflater = getMenuInflater(); @@ -180,6 +207,10 @@ public class CallLogActivity extends AppCompatActivity implements ViewPager.OnPa @Override public boolean onOptionsItemSelected(MenuItem item) { + if (!isVisible()) { + return true; + } + switch (item.getItemId()) { case android.R.id.home: final Intent intent = new Intent(this, DialtactsActivity.class); -- cgit v1.2.3