NavHostFragment.Companion

object NavHostFragment.Companion


Summary

Public methods

final @NonNull NavHostFragment
create(
    @NavigationRes int graphResId,
    @Nullable Bundle startDestinationArgs
)

Create a new NavHostFragment instance with an inflated NavGraph resource.

final @NonNull NavController

Find a NavController given a local Fragment.

Public methods

create

@NonNull
public final NavHostFragment create(
    @NavigationRes int graphResId,
    @Nullable Bundle startDestinationArgs
)

Create a new NavHostFragment instance with an inflated NavGraph resource.

Parameters
@NavigationRes int graphResId

Resource id of the navigation graph to inflate.

@Nullable Bundle startDestinationArgs

Arguments to send to the start destination of the graph.

Returns
NavHostFragment

A new NavHostFragment instance.

findNavController

@NonNull
public final NavController findNavController(@NonNull Fragment fragment)

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
@NonNull 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.