【发布时间】:2019-02-26 06:27:55
【问题描述】:
每次创建片段实例并在您按下返回时重新加载。
如何解决这个问题?
无法在导航控制器中拥有适当的后台堆栈是一个巨大的生产力问题。希望这是一个缺失的功能或故意制作的解决方法...... IMO 这是一个必须具备的,并且必须尽早引入(但是:https://issuetracker.google.com/issues/109856764 说 我们不会允许自定义可预见的未来的交易类型(例如隐藏/显示等)。):(
Nav-Framework is nice, however, it create fragment's view every time
有人有解决办法吗?
我的代码是使用 Navigation 进行导航
object NavigationHelper : Navigational {
override fun moveDownWithPop(view: View,id: Int,popStackId: Int) {
Navigation.findNavController(view).navigate(id,
null,
NavOptions.Builder()
.setPopUpTo(popStackId,
true).build()
)
}
override fun moveDownWithDataPop(view: View,id: Int,popStackId: Int,bundle : Bundle) {
Navigation.findNavController(view).navigate(id,
bundle,
NavOptions.Builder()
.setPopUpTo(popStackId,
true).build()
)
}
override fun moveUp(view: View) {
Navigation.findNavController(view).navigateUp()
}
override fun moveDown(view: View,id: Int) {
Navigation.findNavController(view).navigate(id)
}
override fun moveDown(view: View,id: Int,args : Bundle) {
Navigation.findNavController(view).navigate(id,args)
}
fun navigateGraph(graphId : Int,context : Context){
var finalHost: NavHostFragment? = NavHostFragment.create(graphId)
(context as MainActivity).supportFragmentManager.beginTransaction()
.replace(com.admision.R.id.content,finalHost!!)
.setPrimaryNavigationFragment(finalHost) // this is the equivalent to app:defaultNavHost="true"
.commit()
}
}
我找到了一些博客Why I Will Not Use Architecture Navigation Component
【问题讨论】:
标签: android androidx fragment-backstack android-architecture-navigation