停止使用Navgraph的底部逐步片段重新创建
我有多个片段,例如仪表板,通知和 profile 在底部导航中。我正在使用Navgraph- NavController来控制片段。
我想保存以前片段的状态。
我不想在片段之间切换时再次致电我的API。每当我在片段之间切换时,都会调用当前fragmnent的先前片段和onCreateview的ondestroyview。这就是为什么OnCreateview或OnViewCreated中的所有操作都会再次致电的原因。
我怎么能摆脱它。是否使用 navgraph 进行任何实现,以阻止片段进行再造,
或者有办法不再次称呼这些API。我的意思是次要脱位。
例如: 用户在地图上 fragment,他在Google地图上搜索某些位置,然后移至下一个片段仪表板
我尝试使用
lifecycleScope.launch {
lifecycleScope.launchWhenCreated {
Log.v("LifeCycleState","launchWhenCreated")
}
}
viewLifecycleOwner.lifecycleScope.launch {
lifecycleScope.launchWhenCreated {
Log.v("LifeCycleState","launchWhenCreated in viewLifeCycleOwner")
}
}
I have multiple fragments like Dashboard,Notifications and Profile in Bottom Navigation. I am using NavGraph- NavController to control the fragments.
I want to save the state of previous fragment.
I don't want to call my API's again on Switching between fragments. Whenever I switch between fragment it calls onDestroyView of previous fragment and onCreateView of current Fragmnent . That's why all the operation in onCreateView or onViewCreated will call again.
How could I get rid of it. Is there any implementation using NavGraph that stop fragment from reCeating
Or is there a way to don't call those API's again . I mean to retatin the UIState.
For example:
The user is on Map fragment and he search some location on Google Map and moves to the next fragment Dashboard
I have tried using
lifecycleScope.launch {
lifecycleScope.launchWhenCreated {
Log.v("LifeCycleState","launchWhenCreated")
}
}
viewLifecycleOwner.lifecycleScope.launch {
lifecycleScope.launchWhenCreated {
Log.v("LifeCycleState","launchWhenCreated in viewLifeCycleOwner")
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要遵循多导航图概念。
为基于底部的导航图标创建单独的图表。 ex Home,历史和帐户,因此您可以创建3个图形并将其包含在一个图中。
像这样,
请按照以下内容 sample
You've to follow multi navigations graph concept.
Create separate graphs for the bottom nav icon based. Ex Home, History and Account So you've to create 3 graphs and include in one graph.
Like this
Follow this sample