In a simple app I have Fragments and need to save their status ,
So when the user returns from one fragment to another,
is there still text typed, number chosen, check box marked, etc ... suggestions?
In a simple app I have Fragments and need to save their status ,
So when the user returns from one fragment to another,
is there still text typed, number chosen, check box marked, etc ... suggestions?
overriding onSaveInstanceState()
and saves in onActivityCreated()
: @Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
...
if (savedInstanceState != null) {
//Restore the fragment's state here
}
}
...
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//Save the fragment's state here
}
onSaveInstanceState()
and saves it in the onCreate()
. public void onCreate(Bundle savedInstanceState) {
...
if (savedInstanceState != null) {
//Restore the fragment's instance
mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
...
}
...
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//Save the fragment's instance
getSupportFragmentManager().putFragment(outState, "mContent", mContent);
}
I hope this helps.
I wanted to comment, because respsta was already given in English OS, but as I could not have written here and traduzi.Espero this help.
The code is not in code, if anyone knows why, thank you!