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

public final class NavType.EnumType<D extends Enum<@NonNull ?>> extends NavType.SerializableType

EnumType is used for NavArguments holding enum values.

public final class NavType.ParcelableArrayType<D extends Parcelable> extends NavType

ParcelableArrayType is used for NavArguments which hold arrays of Parcelables.

public final class NavType.ParcelableType<D extends Object> extends NavType

ParcelableType is used for passing Parcelables in NavArguments.

public final class NavType.SerializableArrayType<D extends Serializable> extends NavType

SerializableArrayType is used for NavArguments that hold arrays of Serializables.

public class NavType.SerializableType<D extends Serializable> extends NavType

SerializableType is used for Serializable NavArguments.

Public fields

static final @NonNull NavType<boolean[]>

NavType for storing boolean arrays, corresponding with the "boolean[]" type in a Navigation XML file.

static final @NonNull NavType<@NonNull Boolean>

NavType for storing boolean values, corresponding with the "boolean" type in a Navigation XML file.

static final @NonNull NavType<float[]>

NavType for storing float arrays, corresponding with the "float[]" type in a Navigation XML file.

static final @NonNull NavType<@NonNull Float>

NavType for storing float values, corresponding with the "float" type in a Navigation XML file.

static final @NonNull NavType<int[]>

NavType for storing integer arrays, corresponding with the "integer[]" type in a Navigation XML file.

static final @NonNull NavType<@NonNull Integer>

NavType for storing integer values, corresponding with the "integer" type in a Navigation XML file.

static final @NonNull NavType<long[]>

NavType for storing long arrays, corresponding with the "long[]" type in a Navigation XML file.

static final @NonNull NavType<@NonNull Long>

NavType for storing long values, corresponding with the "long" type in a Navigation XML file.

static final @NonNull NavType<@NonNull Integer>

NavType for storing integer values representing resource ids, corresponding with the "reference" type in a Navigation XML file.

static final @NonNull NavType<String[]>

NavType for storing String arrays, corresponding with the "string[]" type in a Navigation XML file.

static final @NonNull NavType<String>

NavType for storing String values, corresponding with the "string" type in a Navigation XML file.

Public constructors

<T extends Object> NavType(boolean isNullableAllowed)

Public methods

static @NonNull NavType<@NonNull ?>
fromArgType(String type, String packageName)

Parse an argType string into a NavType.

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

Get a value of this type from the bundle

@NonNull String

The name of this type.

boolean

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

abstract @NonNull T

Parse a value of this type from a String.

@NonNull T
parseValue(@NonNull String value, @NonNull T previousValue)

Parse a value of this type from a String and then combine that parsed value with the given previousValue of the same type to provide a new value that contains both the new and previous value.

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

Put a value of this type in the bundle

@NonNull String

Serialize a value of this NavType into a String.

@NonNull String

Public fields

BoolArrayType

public static final @NonNull NavType<boolean[]> BoolArrayType

NavType for storing boolean arrays, corresponding with the "boolean[]" type in a Navigation XML file.

Null values are supported. Default values in Navigation XML files are not supported.

BoolType

public static final @NonNull NavType<@NonNull BooleanBoolType

NavType for storing boolean values, corresponding with the "boolean" type in a Navigation XML file.

Null values are not supported.

FloatArrayType

public static final @NonNull NavType<float[]> FloatArrayType

NavType for storing float arrays, corresponding with the "float[]" type in a Navigation XML file.

Null values are supported. Default values in Navigation XML files are not supported.

FloatType

public static final @NonNull NavType<@NonNull FloatFloatType

NavType for storing float values, corresponding with the "float" type in a Navigation XML file.

Null values are not supported.

IntArrayType

public static final @NonNull NavType<int[]> IntArrayType

NavType for storing integer arrays, corresponding with the "integer[]" type in a Navigation XML file.

Null values are supported. Default values in Navigation XML files are not supported.

IntType

public static final @NonNull NavType<@NonNull IntegerIntType

NavType for storing integer values, corresponding with the "integer" type in a Navigation XML file.

Null values are not supported.

LongArrayType

public static final @NonNull NavType<long[]> LongArrayType

NavType for storing long arrays, corresponding with the "long[]" type in a Navigation XML file.

Null values are supported. Default values in Navigation XML files are not supported.

LongType

public static final @NonNull NavType<@NonNull LongLongType

NavType for storing long values, corresponding with the "long" type in a Navigation XML file.

Null values are not supported. Default values for this type in Navigation XML files must always end with an 'L' suffix, e.g. app:defaultValue="123L".

ReferenceType

public static final @NonNull NavType<@NonNull IntegerReferenceType

NavType for storing integer values representing resource ids, corresponding with the "reference" type in a Navigation XML file.

Null values are not supported.

StringArrayType

public static final @NonNull NavType<String[]> StringArrayType

NavType for storing String arrays, corresponding with the "string[]" type in a Navigation XML file.

Null values are supported. Default values in Navigation XML files are not supported.

StringType

public static final @NonNull NavType<StringStringType

NavType for storing String values, corresponding with the "string" type in a Navigation XML file.

Null values are supported.

Public constructors

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

the type of the data that is supported by this NavType

Public methods

fromArgType

Added in 2.4.0
public static @NonNull NavType<@NonNull ?> fromArgType(String type, String packageName)

Parse an argType string into a NavType.

Parameters
String type

argType string, usually parsed from the Navigation XML file

String packageName

package name of the R file, used for parsing relative class names starting with a dot.

Returns
@NonNull NavType<@NonNull ?>

a NavType representing the type indicated by the argType string. Defaults to StringType for null.

Throws
kotlin.IllegalArgumentException

if there is no valid argType

kotlin.RuntimeException

if the type class name cannot be found

get

Added in 1.0.0
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

getName

Added in 1.0.0
public @NonNull String getName()

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

isNullableAllowed

Added in 1.0.0
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.

parseValue

Added in 1.0.0
public abstract @NonNullparseValue(@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
@NonNull T

parsed value of the type represented by this NavType

Throws
kotlin.IllegalArgumentException

if value cannot be parsed into this type

parseValue

Added in 2.6.0
public @NonNullparseValue(@NonNull String value, @NonNull T previousValue)

Parse a value of this type from a String and then combine that parsed value with the given previousValue of the same type to provide a new value that contains both the new and previous value.

By default, the given value will replace the previousValue.

Parameters
@NonNull String value

string representation of a value of this type

@NonNull T previousValue

previously parsed value of this type

Returns
@NonNull T

combined parsed value of the type represented by this NavType

Throws
kotlin.IllegalArgumentException

if value cannot be parsed into this type

put

Added in 1.0.0
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 String key

bundle key

@NonNull T value

value of this type

serializeAsValue

Added in 2.6.0
public @NonNull String serializeAsValue(@NonNull T value)

Serialize a value of this NavType into a String.

By default it returns value of kotlin.toString or null if value passed in is null.

This method can be override for custom serialization implementation on types such custom NavType classes.

Parameters
@NonNull T value

a value representing this NavType to be serialized into a String

Returns
@NonNull String

serialized String value of value

toString

public @NonNull String toString()