I am adding the next fragment when clicked on textView in each fragment.
My Flow is MainActivity => Fragment A => Fragment B => Fragment C => Fragment D
But every time I click on textView in Fragment D, Fragment D gets added and back stack count increases. I don't have any click listener in Fragment D. So why this is happing?
This is my MainActivity =>
buttonAddFragment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AFragment fragment = new AFragment();
addFragment(fragment, "MainActivity");
}
});
public void addFragment(Fragment fragment, String callingFrom) {
Log.e("Call =>", callingFrom);
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragmentContainer, fragment, "demoFragment");
fragmentTransaction.addToBackStack("tag");
fragmentTransaction.commit();
}
Fragment A =>
mTextViewClick = view.findViewById(R.id.mTextViewClick);
mTextViewClick.setText("A Fragment");
mTextViewClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BFragment fragment=new BFragment();
((MainActivity)getActivity()).addFragment(fragment,"Fragment A");
}
});
All fragments have the same code as Fragment A