Persist selected group on rotation

It was all about timing of restoration.  We did have the code to restore it,
but it should have been done before mAdapter.setSelectedGroup().

Also switched from Bundle.putString() to putParcelable().
(putParcelable accepts null -- so the change should be safe.)

(This CL also restores the activated item on the group browse list, although
we don't set proper background to it.)

Bug 5137176

Change-Id: I735f80419c60bb3dd5e760c639900b4eba1ef6c5
diff --git a/src/com/android/contacts/group/GroupBrowseListFragment.java b/src/com/android/contacts/group/GroupBrowseListFragment.java
index 49835ef..2b9c594 100644
--- a/src/com/android/contacts/group/GroupBrowseListFragment.java
+++ b/src/com/android/contacts/group/GroupBrowseListFragment.java
@@ -101,6 +101,15 @@
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
+        if (savedInstanceState != null) {
+            mSelectedGroupUri = savedInstanceState.getParcelable(EXTRA_KEY_GROUP_URI);
+            if (mSelectedGroupUri != null) {
+                // The selection may be out of screen, if rotated from portrait to landscape,
+                // so ensure it's visible.
+                mSelectionToScreenRequested = true;
+            }
+        }
+
         mRootView = inflater.inflate(R.layout.group_browse_list_fragment, null);
         mEmptyView = (TextView)mRootView.findViewById(R.id.empty);
 
@@ -137,12 +146,6 @@
         });
         setAddAccountsVisibility(!ContactsUtils.areAccountsAvailable(mContext));
 
-        if (savedInstanceState != null) {
-            String groupUriString = savedInstanceState.getString(EXTRA_KEY_GROUP_URI);
-            if (groupUriString != null) {
-                mSelectedGroupUri = Uri.parse(groupUriString);
-            }
-        }
         return mRootView;
     }
 
@@ -300,12 +303,7 @@
     @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
-        if (mSelectedGroupUri != null) {
-            String uriString = mSelectedGroupUri.toString();
-            if (!TextUtils.isEmpty(uriString)) {
-                outState.putString(EXTRA_KEY_GROUP_URI, uriString);
-            }
-        }
+        outState.putParcelable(EXTRA_KEY_GROUP_URI, mSelectedGroupUri);
     }
 
     public void setAddAccountsVisibility(boolean visible) {