android - 片段 - 在创建片段之前取消片段事务
问题描述
MyFragment
有layout_my_fragment.xml
一个 WebView 小部件。MyFragment
不会膨胀视图本身,它使用继承:
MyFragment <- ParentFragment <- GrandParentFragment (layout is inflated here)
目标是在扩展其布局之前检查手机是否启用了 WebView (这会使应用程序崩溃)。
到目前为止我的解决方案:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
checkWebviewIsEnabled()
return super.onCreateView(inflater, container, savedInstanceState)
}
override fun checkWebviewIsEnabled(): Boolean {
if(!isWebviewEnabled(requireActivity())) {
findNavController().popBackStack()
}
return true
}
findNavController().popBackStack()
,这是退出片段的正常方式,被调用但不做任何事情并且return true
被调用。我怀疑这是因为这种方式仅在创建片段后才有效。
那么如何在扩展其布局之前取消片段创建?
解决方案
推荐阅读
- android - 如何在android中一起播放相同的动画
- python - 无法在 Jupyter Notebook 上安装 dataprep 库
- python - 如何从另一个 Python 脚本访问 Python 脚本的动态变量?
- javascript - 我如何用 Jest 测试 React 路由器
- python - 在 matplotlib 中显示折线图特定点的文本
- php - 在 WordPress 的现有 wordpress 侧边栏搜索中添加自定义属性搜索
- javascript - 使用数组时 parentElement.remove() 未定义
- node.js - Expo,nodejs,Heroku Server“套接字连接错误”
- bash - 使用 bash 数组从文件中循环 IP 地址
- javascript - SCRAM-SERVER-FIRST-MESSAGE:客户端密码必须是字符串