Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

NavArgument

public final class NavArgument
extends Object

java.lang.Object
   ↳ androidx.navigation.NavArgument


NavArgument denotes an argument that is supported by a NavDestination.

A NavArgument has a type and optionally a default value, that are used to read/write it in a Bundle. It can also be nullable if the type supports it.

Summary

Nested classes

class NavArgument.Builder

A builder for constructing NavArgument instances. 

Public methods

boolean equals(Object o)
Object getDefaultValue()

Returns the default value of this argument or `null` if it doesn't have a default value.

NavType<?> getType()

Get the type of this NavArgument.

int hashCode()
boolean isDefaultValuePresent()

This method can be used to distinguish between a default value of `null` and an argument without an explicit default value.

boolean isNullable()

Check if this argument allows passing a `null` value.

Inherited methods

Public methods

equals

public boolean equals (Object o)

Parameters
o Object

Returns
boolean

getDefaultValue

public Object getDefaultValue ()

Returns the default value of this argument or `null` if it doesn't have a default value. Use isDefaultValuePresent() to distinguish between `null` and absence of a value.

Returns
Object The deafult value assigned to this argument.

getType

public NavType<?> getType ()

Get the type of this NavArgument.

Returns
NavType<?> the NavType object denoting the type that can be help in this argument.

hashCode

public int hashCode ()

Returns
int

isDefaultValuePresent

public boolean isDefaultValuePresent ()

This method can be used to distinguish between a default value of `null` and an argument without an explicit default value.

Returns
boolean true if this argument has a default value (even if that value is set to null), false otherwise

isNullable

public boolean isNullable ()

Check if this argument allows passing a `null` value.

Returns
boolean true if `null` is allowed, false otherwise