The best practice to instantiate a fragment is:
public static MyFragment newInstance(int someInt) {
MyFragment myFragment = new MyFragment();
Bundle args = new Bundle();
args.putInt("someInt", someInt);
myFragment.setArguments(args);
return myFragment;
}
Then via the arguments
is available even if the OS recreates the fragment.
Question:
The onCreate
already accepts a Bundle
and we can use saveInstanceState
to save the data. So what is the difference with the Bundle
we set in the arguments?
If I keep using the arguments
during the activity/fragment lifecycle and do not use the save/restore instance bundle would that create any problems?