答案 0 :(得分:0)
在你的片段旁边按下片段并将代码放在那里。
public class MyFragment extends BaseFragment {
/**
* Back pressed send from activity.
*
* @return if event is consumed, it will return true.
*/
@Override
public boolean onBackPressed() {
startActivity(new Intent(this, blabla.class));
//or you could say finish();
//or you could say moveTaskToBack(true);
}
答案 1 :(得分:0)
请检查以下可能的情况....
检查您使用的片段方法replace or Add
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.rlContainer, fragment); // replace the existing one
启用backStack
支持,然后在backPress
上显式加载相同的片段
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.rlContainer, fragment);
//ft.addToBackStack(null); // will add to the fragment stack
ft.commitAllowingStateLoss();
如果您启用backStack
支持,则可以查看计数
FragmentManager fm = getFragmentManager(); // or 'getSupportFragmentManager();'
int count = fm.getBackStackEntryCount();
for(int i = 0; i < count; ++i) {
fm.popBackStack();
}