Everytime fragment instance is created and reloading when you press back.
How to overcome this issue?
Inability of having proper backstack in nav controller is a huge productivity issue. Hope it's a missing feature or a work-around made on purpose... IMO this is a must-have and has to be introduced sooner rather than later (however: https://issuetracker.google.com/issues/109856764 says We won't be allowing customization of the transaction type (such as hiding/showing, etc) for the foreseeable future.) :(
Nav-Framework is nice, however, it create fragment's view every time
Does anyone has solution?
My code is to navigate using 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()
}
}
i found some blog Why I Will Not Use Architecture Navigation Component