There are 3 fragments: A, B, C.
All are hosted on one Activity , from A I call B, then from B I call C (A -> B -> C).
When you press the "back" button in the fragment C, you must skip the fragment B and return immediately to A.
I have been looking for information for a long time, either posing the problem is different and the solution is not suitable, or they suggest calling popBackStack two times in a row, which, in my opinion, is terrible, and I need to skip program B exactly programmatically, not visually, so that the user doesn’t notice.
Code below.
Fragment A , Fragment B call:
this.mFuelCardAuthBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MainFragment.this.getActivity().getFragmentManager() .beginTransaction() .replace(R.id.activity_main_fragment_container, AuthProgressFragment.newInstance()) .addToBackStack(MainFragment.class.getSimpleName()) .commit(); } }); Fragment B , invocation of fragment C:
this.getActivity().getFragmentManager().beginTransaction() .replace(R.id.activity_main_fragment_container, AuthSuccessFragment.newInstance(AppConst.FUEL_CARD_AUTH_TYPE)) .addToBackStack(AuthProgressFragment.class.getCanonicalName()) .commit(); In an Activity host, the handling of pressing the Back key:
@Override public void onBackPressed() { if (this.getFragmentManager().getBackStackEntryCount() > 1) { this.getFragmentManager().popBackStack(); } else { super.onBackPressed(); } } In general, there is a feeling that the return processing for back is not implemented correctly for me, although it works, so I would be grateful if you send it to the right path in this topic.
Thank.