0
Hi, I have an app that uses NavigationDrawer
, I have a fragment that has a AlertDialog
, and in it I have two send and cancel buttons, no cancel wish back to the desired main Fragment.
I managed to do it in a way that he’s coming back only the title on Toolbar is the old one still. Then I have to go back again so he can stay at the Ragment.
Man OnBackPressed
of mainActivity
:
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
//retornar o drawer
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
// retorna todos os fragments que estão em backStack
} else if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
toolbar.setTitle("Expresso1002");
} else {
super.onBackPressed();
}
}
And my exit from the cancel button:
btnCancelar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_principal, new principal());
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
I resolved so:
getActivity().setTitle("Expresso 1002");
, Only when he comes back he opens another identity on top.– Aristófanes Melo
Note your transition between fragments. That is, note if you are using
fragmentTransaction.add
orfragmentTransaction.repleace
. I noticed that you use Navigationdrawer for your transitions. So I recommend using whenever possiblefragmentTransaction.repleace
– André alas
I managed to settle by putting:
getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
below thefragmentTransaction.commit();
, vlw bro.– Aristófanes Melo