android - 删除 OnBackPressedCallback 片段管理器
问题描述
我有一个从互联网加载数据的活动,它工作正常,除了必须双击后退按钮来完成它。我还注意到,在未连接到互联网的活动中,后退按钮从第一次单击开始起作用。调试时我发现片段管理器回调正在处理第一次点击
FragmentManager.this.handleOnBackPressed();
从源头
void handleOnBackPressed() {
// First, execute any pending actions to make sure we're in an
// up to date view of the world just in case anyone is queuing
// up transactions that change the back stack then immediately
// calling onBackPressed()
execPendingActions();
if (mOnBackPressedCallback.isEnabled()) {
// We still have a back stack, so we can pop
popBackStackImmediate();
} else {
// Sigh. Due to FragmentManager's asynchronicity, we can
// get into cases where we *think* we can handle the back
// button but because of frame perfect dispatch, we fell
// on our face. Since our callback is disabled, we can
// re-trigger the onBackPressed() to dispatch to the next
// enabled callback
mOnBackPressedDispatcher.onBackPressed();
}
}
虽然我不使用片段
解决方案
推荐阅读
- node.js - 使用 NodeJS 连接到在线托管的 PostgresSQL
- swift - 根据特定条件配置 Xcode 是否加载 xcframework?
- reactjs - 在表单中挣扎(和反应钩子)
- node.js - Nodemailer 不从远程服务器发送邮件:错误:连接超时
- sql - 如何制作会计余额报告?
- c# - 如何从 Button Click 事件中获取特定的 PictureBox?
- python - pygame混音器中没有添加音乐文件时出现的AttributeError问题如何解决?
- reactjs - 如何在渲染时在 textarea 中显示内容的顶部?
- sql - 如何处理增量数据的行号窗口函数
- javascript - 如何在javascript中将我的嵌套对象转换为数组