I have an activity, which instantiates 4 different fragments based on button clicks. I have to pass additional values to my fragment which is currently active.
Initially, when I pass values via setArguments, the values are being passed. But 2nd time the values are not passed to Fragment.
I tried to Log and put breakpoints in onCreate and onCreateView methods, but these methods are not being called at all 2nd time.
Here is my code
Code in Activity
Bundle bundle = new Bundle();
bundle.putInt("from", "1");
bundle.putString("label","One");
MyFragment1 myFragment1 = new MyFragment1();
myFragment1.setArguments(bundle);
getSupportFragmentManager()
.beginTransaction()
.addToBackStack(null)
.replace(R.id.fragment1, myFragment1)
.commitAllowingStateLoss();
Code in Fragment
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle b = getArguments();
if(b!=null)
{
}
}