There are similar questions, but none of the are solving my issue. My app flow is following:
Activity home starts Activity B(which does the setup work) In activity B hosts three screens as fragments... Fragment1 -> fragment2-> fragment 3.
This is how I make fragments. I am not using replace.just adding it.
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment fragment = null;
if (getFragType().equals("simple")) {
fragment = new SimpleFragment().newInstance();
}
if (getFragType.equals("inter")) {
if (getFragType.getComponent().equals("con"))
fragment = new SetupConFragment().newInstance();
else if (getFragType.getComponent().equals("ben"))
fragment = new SetupBenageFragment().newInstance();
}
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}
Fragment3 has a done button. So once all the 3 steps are done from fragment 3 am launching a new activity C.
The issue is:-- From the activity C , if the user presses the back button, it diplays fragment 2, then fragment 1. Ideally once the user is in Activity C, back press should just exit the screen I have used all combinations of the intent flags, but it is not helping.
And this is on my button click.
Intent launch = new Intent(mContext, MainActivity.class);
launch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
launch.putExtra("Exit me", true);
mContext.startActivity(launch);
((ConfigureActivity)mContext).finish();
Any help will be appreciated.
You can do this way:
Clear Fragment stack:
getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
Clear Activity stack:
Intent intent = new Intent(Your_Current_Activity.this, Your_Destination_Activity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Hope this will help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With