android - 使用片段和活动android的回栈和回压
问题描述
我在一个活动中使用了 3 个片段,使用来自第 3 个片段的帧布局,它应该转到一个活动,然后在该活动的后按时,它应该重定向到第 3 个片段,并且从第 3 个片段的后按它应该重定向到第一个片段而没有空白屏幕?.我有黑屏和循环
解决方案
覆盖 onBackPressed() 并在内部处理替换。
@Override
public void onBackPressed() {
//Check current fragment
Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
if(f instanceof FragmentThird) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack if needed
transaction.replace(R.id.fragment_container, fragmentFirst);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
return;
}
推荐阅读
- vue.js - Nuxt.js:关于 nuxt-link 到动态路由的新手问题
- css - 使用 Bootstrap 在视网膜显示上的 CSS 断点
- node.js - 我的消息在 node.js/discord.js 中重复了很多次
- python - 适用于具有许多特征的小数据的回归方法
- gimp - gimp:几个相邻图像的层大小
- angular - ng test angular 7 无法识别窗口对象中的用户定义方法
- c# - 调用 .NET Core 中缺少的端点会产生 404,但也可以作为对 Angular 的响应
- flutter - 从另一个属性引用属性
- python - 将密码存储在变量中是否危险?
- javascript - Switch 语句 (javaScript) 只会显示 else 条件