I\'m creating a file manager app for Android, and two classes below are the majority of the logic that goes into doing that. What I\'m doing is that on startup of the Conten
use this for save state of fragment on orientation.
onCreate(Bundle save)
{
super.onCreate(save);
setRetainInstance(true);
}
this worked for me
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
onCreate(savedInstanceState);
}
and in manifest file inside your Activity tag
android:configChanges="orientation|screenSize"
Just posting this since this is a major concerns faced in both work and interviews :) Before API 13 we were using onRetainNonConfigurationInstance() which is deprecated (This method was relate to Activity which is now moved in to fragment)and now we have a new method know as setRetainInstance() (method part of fragment class)this will save the state of fragments even after the activity creation.