在FragmentActivity的fragment跳转的时候添加到运行栈,
public void switchFrag(BaseFragment to) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.frag_login_content, to)
.addToBackStack(null).commit();
}
在返回器里popStack
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// 返回上一个fragment
popBackStack();
return true;
}
return super.onKeyDown(keyCode, event);
}
原文地址:http://blog.csdn.net/u012102504/article/details/46443319