在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); }