Skip to content

Instantly share code, notes, and snippets.

@qamarelsafadi
Last active June 14, 2022 07:38
Show Gist options
  • Save qamarelsafadi/05a00439c4d926e2d9948e8aca762c29 to your computer and use it in GitHub Desktop.
Save qamarelsafadi/05a00439c4d926e2d9948e8aca762c29 to your computer and use it in GitHub Desktop.
This gist file will include all Navigation Component usefull Extensions.
/*
Qamar A. Safadi
*/
fun NavController.safeNavigateWithClearBackStack(
@IdRes currentDestinationId: Int,
@IdRes id: Int,
args: Bundle? = null
) {
if (currentDestinationId == currentDestination?.id) {
val navOptions = NavOptions.Builder()
.setPopUpTo(R.id.main_nav_xml, true).build() // id here is your navigation id in navigation.xml
navigate(id, args, navOptions)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment