NavType

public abstract class NavType<T extends Object>

Known direct subclasses
NavType.ParcelableArrayType

ParcelableArrayType is used for NavArguments which hold arrays of Parcelables.

NavType.ParcelableType

ParcelableType is used for passing Parcelables in NavArguments.

NavType.SerializableArrayType

SerializableArrayType is used for NavArguments that hold arrays of Serializables.

NavType.SerializableType

SerializableType is used for Serializable NavArguments.

Known indirect subclasses
NavType.EnumType

EnumType is used for NavArguments holding enum values.


NavType denotes the type that can be used in a NavArgument.

There are built-in NavTypes for primitive types, such as int, long, boolean, float, and strings, parcelable, and serializable classes (including Enums), as well as arrays of each supported type.

You should only use one of the static NavType instances and subclasses defined in this class.

Parameters
<T extends Object>

the type of the data that is supported by this NavType

Summary

Nested types

NavType.Companion
NavType.EnumType

EnumType is used for NavArguments holding enum values.

NavType.ParcelableArrayType

ParcelableArrayType is used for NavArguments which hold arrays of Parcelables.

NavType.ParcelableType

ParcelableType is used for passing Parcelables in NavArguments.

NavType.SerializableArrayType

SerializableArrayType is used for NavArguments that hold arrays of Serializables.

NavType.SerializableType

SerializableType is used for Serializable NavArguments.

Public fields

boolean

Check if an argument with this type can hold a null value.

@NonNull String

The name of this type.

Public constructors

<T extends Object> NavType(boolean isNullableAllowed)

Public methods

abstract @Nullable T
get(@NonNull Bundle bundle, @NonNull String key)

Get a value of this type from the bundle

abstract @NonNull T

Parse a value of this type from a String.

abstract void
put(@NonNull Bundle bundle, @NonNull String key, @NonNull T value)

Put a value of this type in the bundle

@NonNull String

Public fields

isNullableAllowed

@NonNull
public boolean isNullableAllowed

Check if an argument with this type can hold a null value.

Returns
boolean

Returns true if this type allows null values, false otherwise.

name

@NonNull
public @NonNull String name

The name of this type.

This is the same value that is used in Navigation XML argType attribute.

Returns
@NonNull String

name of this type

Public constructors

public final <T extends Object> NavType(boolean isNullableAllowed)
Parameters
<T extends Object>

the type of the data that is supported by this NavType

Public methods

get

@Nullable
public abstract T get(@NonNull Bundle bundle, @NonNull String key)

Get a value of this type from the bundle

Parameters
@NonNull Bundle bundle

bundle to get value from

@NonNull String key

bundle key

Returns
T

value of this type

parseValue

@NonNull
public abstract T parseValue(@NonNull String value)

Parse a value of this type from a String.

Parameters
@NonNull String value

string representation of a value of this type

Returns
T

parsed value of the type represented by this NavType

Throws
kotlin.IllegalArgumentException

if value cannot be parsed into this type

put

@NonNull
public abstract void put(@NonNull Bundle bundle, @NonNull String key, @NonNull T value)

Put a value of this type in the bundle

Parameters
@NonNull Bundle bundle

bundle to put value in

@NonNull