Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

Android kotlin - Navhost fragment - Popupto from menu

I am working on Android and I want to reset the navigate back to a intro fragment from anywhere in my application from a drawer menu item.

I saw the popupto option from an action in a fragment but I don't know how to use it in the menu item or even if it possible. May be this is not the right approach, I just want to be able to reset the stack and go back to a defined fragment from a click on a item menu.

Thx Regards.

question from:https://stackoverflow.com/questions/65873517/android-kotlin-navhost-fragment-popupto-from-menu

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use this code snippet when menuItem Clicked

navController.popBackStack(navController.graph.startDestination,false)

for any case use this code snippet for pop up to some fragment

val navOptions = NavOptions.Builder().setPopUpTo(R.id.popUpToFragmentId, true).build()
navController.navigate(R.id.destinationFragmentId, navOptions)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...