I realise this question has been asked before however the previous answers have gotten me so far. The scenario is as follows: we have a dashboard fragment (A), which leads a user to a login screen (B). On successful login they go to a listview (c). On backpress I would like to return to A, as the user will not need to see the login screen again. In addition on successful login we store the details in shared preferences and automate the login in B next time, which all works as planned.
I have the following FragmentHelper method:
public static void goToNextFragement(Fragment fragment, int container, boolean addToBackStack, Fragment ctx)
{
// Create new fragment and transaction
FragmentTransaction transaction = ctx.getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(container, fragment);
if(addToBackStack)
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
In the transaction from B to C I set the Boolean addToBackStack as false so that the transaction.addToBackStack(null);
is not called. This again works well but after is where my problem starts.
When the user presses back on C and returns to A I can still see the inflated view of C under the view of A.
Any help would be appreciated. I hope my diagram helps keep this simple.