I got from Are fragments saved by default with savedInstanceState? that to "To keep a fragment when an Activity gets destroyed, so it automatically reataches, you should call `Fragment.setRetainInstance(true)'"
However on https://developers.facebook.com/docs/android/login-with-facebook/v2.1#dialogs , they did not use this method in the constructor of the fragment but was still able to retain the fragment in oncreate Their code for doing so is
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
// Add the fragment on initial activity setup
mainFragment = new MainFragment();
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, mainFragment)
.commit();
} else {
// Or set the fragment from restored state info
mainFragment = (MainFragment) getSupportFragmentManager()
.findFragmentById(android.R.id.content);
}
}
Does anyone what trick they used to retain that fragment without using setretaininstance?