Fix for "Can not perform this action after onSaveInstanceState"
We seem to be getting a view pager event after onSaveInstanceState.
Clear the view pager listener in onSaveInstanceState to avoid this,
which is what we do with ActionBarAdapter too.
Bug 5161276
Change-Id: Ic20188c4f6ee0b60c6b6c9ea98709039a68d8073
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 1da1c97..68e9cbb 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -156,6 +156,7 @@
/** ViewPager for swipe, used only on the phone (i.e. one-pane mode) */
private ViewPager mTabPager;
private TabPagerAdapter mTabPagerAdapter;
+ private final TabPagerListener mTabPagerListener = new TabPagerListener();
private ContactDetailLayoutController mContactDetailLayoutController;
@@ -315,7 +316,7 @@
mTabPager = getView(R.id.tab_pager);
mTabPagerAdapter = new TabPagerAdapter();
mTabPager.setAdapter(mTabPagerAdapter);
- mTabPager.setOnPageChangeListener(new TabPagerListener());
+ mTabPager.setOnPageChangeListener(mTabPagerListener);
final String FAVORITE_TAG = "tab-pager-favorite";
final String ALL_TAG = "tab-pager-all";
@@ -450,6 +451,9 @@
// Re-register the listener, which may have been cleared when onSaveInstanceState was
// called. See also: onSaveInstanceState
mActionBarAdapter.setListener(this);
+ if (mTabPager != null) {
+ mTabPager.setOnPageChangeListener(mTabPagerListener);
+ }
// Current tab may have changed since the last onSaveInstanceState(). Make sure
// the actual contents match the tab.
updateFragmentsVisibility();
@@ -1527,6 +1531,9 @@
// in order to avoid doing fragment transactions after it.
// TODO Figure out a better way to deal with the issue.
mActionBarAdapter.setListener(null);
+ if (mTabPager != null) {
+ mTabPager.setOnPageChangeListener(null);
+ }
}
@Override