i have one activity, which runs fragment A at start in a RelativeLayout,
after that, inside this fragment, i try to open another fragment B, which is somehow an overlay only, it runs in another RelativeLayout, to look above fragment A, so far, all is working good, but the problem is in the onBackPressed():
I open the overlay fragment B, then i press back button, but it closes fragment A only.
Here is my activity's xml
<RelativeLayout
android:id="@+id/main_fragment_replacement"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
<RelativeLayout
android:background="#0000"
android:id="@+id/overlay_fragment_replacement"
android:layout_width="match_parent"
android:layout_height="match_parent">
I think this should explain it, but i'm up to provide any additional info.
When adding Fragments, you can add them to your backstack.
getSupportManager()
.beginTransaction()
.replace(R.id.container, fragment)
.addToBackStack(null)
.commit();
Then you can simply check how many fragment are in your backstack and remove e.g. Fragment B when 2 when the backstack contains two fragments.