Created
November 8, 2012 09:10
-
-
Save billynyh/4037680 to your computer and use it in GitHub Desktop.
iosched 2012 - handle fragment in onSaveInstanceState
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// iosched/android/src/com/google/android/apps/iosched/ui/HomeActivity.java | |
@Override | |
protected void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
// Since the pager fragments don't have known tags or IDs, the only way to persist the | |
// reference is to use putFragment/getFragment. Remember, we're not persisting the exact | |
// Fragment instance. This mechanism simply gives us a way to persist access to the | |
// 'current' fragment instance for the given fragment (which changes across orientation | |
// changes). | |
// | |
// The outcome of all this is that the "Refresh" menu button refreshes the stream across | |
// orientation changes. | |
if (mSocialStreamFragment != null) { | |
getSupportFragmentManager().putFragment(outState, "stream_fragment", | |
mSocialStreamFragment); | |
} | |
} | |
@Override | |
protected void onRestoreInstanceState(Bundle savedInstanceState) { | |
super.onRestoreInstanceState(savedInstanceState); | |
if (mSocialStreamFragment == null) { | |
mSocialStreamFragment = (SocialStreamFragment) getSupportFragmentManager() | |
.getFragment(savedInstanceState, "stream_fragment"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment