首先替换片段container_view,那时我们添加名称,如“后期交易”
getSupportFragmentManager().beginTransaction().replace(R.id.container_view,
profileFragment, "Profile").addToBackStack("Later Transaction").commit();
然后在后面按下按钮使用后来的事务名称弹出返回堆栈
int count = getSupportFragmentManager().getBackStackEntryCount();
if(count > 1) {
getSupportFragmentManager().popBackStack("Later Transaction",
FragmentManager.POP_BACK_STACK_INCLUSIVE);
} else {
DialogUtils.show(HomeActivity.this,
getString(R.string.exit_app_message), getString(R.string.alert),
"Yes","No", new DialogUtils.ActionListner() {
@Override
public void onPositiveAction() {
finish();
}
@Override
public void onNegativeAction() {
}
});
}