So the problem is not a technical issue, but more of an aesthetic kind.
I am passing data from one fragment to another fragment. So there are 3 fragments in total and the first two are calling the same 3rd fragment, so to identify in the third fragment from which of the first two it was invoked I am using the following code
in the first fragment
Bundle bundle = new Bundle();
bundle.putBoolean("isFirst", true)
Fragment fragment = new ThirdFragment();
fragment.setArguments(bundle);
loadFragment(fragment);
and in the second fragment as
Bundle bundle = new Bundle();
bundle.putBoolean("isFirst", false)
Fragment fragment = new ThirdFragment();
fragment.setArguments(bundle);
loadFragment(fragment);
and in the third fragment
Bundle bundle = this.getArguments();
Boolean isFirst = bundle.getBoolean("isFirst",false);
if(isFirst){
....
} else{
....
}
the code works fine but I think there should be a more elegant way of doing it. If not atleast make the whole thing into one line without additional declarations such as Bundle bundle and Fragment fragment
for example something like
loadFragment(new ThirdFragment().setArguments(new Bundle().putBoolean("isFirst",true)));
I am relatively new to android and java programming so please don't be harsh.