Reuse fragments when rotating contact card on phone
- Part 1 of refactoring contact card fragment code, Part 2 will be refactoring the tablet code to fix bug 5082871 - ContactDetailActivity should always have non-null fragments after onCreate() (either retrieved from Fragment Manager or created dynamically) - New view pager adapter that returns views that contain existing fragments (instead of generating new fragments) - The main reason for these changes is that when we create fragments dynamically (necessary for the ViewPager otherwise the fragment from XML will already have a parent), the view ID will be the pager view ID. When we rotate, the fragments are already defined in XML for the fragment carousel and already have different view IDs, so it won't restore properly. We can't put the pager view ID in the fragment carousel layout, otherwise the ContactDetailActivity will try to cast it to a ViewPager. Alternatively, if we make both layouts rely on dynamically created fragments, the problem becomes the fact that once fragments are added to the fragment manager, they cannot be retrieved and added again to a different parent if there's a different layout (exception is thrown). Thus, the solution is to have the same parent container in both phone portrait and landscape layouts. - Also it is unclear what was happening to the fragments on rotation (they weren't being restored but weren't being removed from the FragmentManager). We can remove the hack now that would store the ViewPager fragment tags in the saved instance bundle and manually remove those fragments from the FragmentManager after an orientation change. - In onCreate() of the ContactDetailActivity, if this is a restored instance, then inflate the correct layout right away so the fragments can find the parent containers. - Save/restore ListView state on rotation - Save/restore selected tab for contact with social updates - Clean up computation code for FragmentCarousel by moving it to onMeasure() method Bug: 4976082 Bug: 4686406 Bug: 5082871 Change-Id: I7840b1dd1110da4dcc28ebabe3fc2739ff11c2f2
Loading
Please register or sign in to comment