NavHostFragment.Companion

object NavHostFragment.Companion


Summary

Public functions

NavHostFragment
create(@NavigationRes graphResId: Int, startDestinationArgs: Bundle?)

Create a new NavHostFragment instance with an inflated NavGraph resource.

NavController

Find a NavController given a local Fragment.

Public functions

create

fun create(@NavigationRes graphResId: Int, startDestinationArgs: Bundle? = null): NavHostFragment

Create a new NavHostFragment instance with an inflated NavGraph resource.

Parameters
@NavigationRes graphResId: Int

Resource id of the navigation graph to inflate.

startDestinationArgs: Bundle? = null

Arguments to send to the start destination of the graph.

Returns
NavHostFragment

A new NavHostFragment instance.

findNavController

fun findNavController(fragment: Fragment): NavController

Find a NavController given a local Fragment.

This method will locate the NavController associated with this Fragment, looking first for a NavHostFragment along the given Fragment's parent chain. If a NavController is not found, this method will look for one along this Fragment's view hierarchy as specified by Navigation.findNavController.

Parameters
fragment: Fragment

the locally scoped Fragment for navigation

Returns
NavController

the locally scoped NavController for navigating from this Fragment

Throws
kotlin.IllegalStateException

if the given Fragment does not correspond with a NavHost or is not within a NavHost.