Android导航-是否可以使用popBackStack方法从上部片段还原捆绑包? [英] Android Navigation - Is it possible to restore a bundle from upper fragment with popBackStack method?

查看:119
本文介绍了Android导航-是否可以使用popBackStack方法从上部片段还原捆绑包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从上层片段传递到下层片段时,我试图在片段之间传递数据,但是我不想使用Navigation方法.它为流程历史记录添加了一个新的目的地,但是我想回到上一个片段,恢复它的数据并刷新视图. 可以使用NavController和popBackStack方法来做到这一点吗?

I was trying to pass data between fragments while I was passing from upper fragment to down fragment, but I don't want to use the navigate method. It adds a new destination to the process history, but I want back to the previous fragment, restore it data and refresh the view. Is it possible to do it with NavController and popBackStack method?

推荐答案

我也遇到了同样的问题,并且在下面的解决方案中使用了该解决方案,但是我不确定它的正确方法与否.

I also got same problem and I have used below solution which is working, But i am not sure its correct way or not.

val navOptions = NavOptions.Builder().setPopUpTo(R.id.id_of_fragment_one, true).build()
view?.findNavController()?.navigate(R.id.id_of_fragment_one, bundleOf("id" to model), navOptions)

这篇关于Android导航-是否可以使用popBackStack方法从上部片段还原捆绑包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆