I'm opening fragments
containing list, over and over again, then, ultimately, I want to clear the fragment
stack to open a new Fragment
once I reach the end of those fragments containing a list.
I don't know if i'm being clear so here is what I'm doing currently:
private final BroadcastReceiver onReceiveLaunchIncident = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
// Select the correct item from the DrawerLayout
selectItem(drawerList.indexOf("Patrol"));
}
};
Currently it goes this way when I enter my BroadcastReceiver
Fragment D ---> Fragment A ---> Fragment E
And I want it to go this way:
Fragment D ---> Fragment E
private void selectItem(final int position) {
addToDrawerIfNotExist(position);
if (mDrawerListChild.getCheckedItemPosition() == position) {
Log.i(TAG, "Same position selected in drawer");
}
mDrawerListChild.setItemChecked(position, true);
mDrawerLayout.closeDrawer(mDrawerLinear);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out);
BackHandledFragment fragment = fragmentListString.get(fragmentList.get(position));
ft.replace(R.id.content_frame, fragment, fragment.getTagText())
.commitAllowingStateLoss();
}
}, 300);
}