NavType

public abstract class NavType
extends Object

java.lang.Object
   ↳ androidx.navigation.NavType<T>


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.

Summary

Nested classes

class NavType.EnumType<D extends Enum>

EnumType is used for NavArguments holding enum values. 

class NavType.ParcelableArrayType<D extends Parcelable>

ParcelableArrayType is used for NavArguments which hold arrays of Parcelables. 

class NavType.ParcelableType<D>

ParcelableType is used for passing Parcelables in NavArguments. 

class NavType.SerializableArrayType<D extends Serializable>

SerializableArrayType is used for NavArguments that hold arrays of Serializables. 

class NavType.SerializableType<D extends Serializable>

SerializableType is used for Serializable NavArguments. 

Fields

public static final NavType<boolean[]> BoolArrayType

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

public static final NavType<Boolean> BoolType

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

public static final NavType<float[]> FloatArrayType

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

public static final NavType<Float> FloatType

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

public static final NavType<int[]> IntArrayType

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

public static final NavType<Integer> IntType

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

public static final NavType<long[]> LongArrayType

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

public static final NavType<Long> LongType

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

public static final NavType<Integer> ReferenceType

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

public static final NavType<String[]> StringArrayType

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

public static final NavType<String> StringType

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

Public methods

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

Parse an argType string into a NavType.

abstract T get(Bundle bundle, String key)

Get a value of this type from the bundle

abstract String getName()

Returns the name of this type.

boolean isNullableAllowed()

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

abstract T parseValue(String value)

Parse a value of this type from a String.

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

Put a value of this type in he bundle

String toString()

Inherited methods

Fields

BoolArrayType

public static final 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 NavType<Boolean> BoolType

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

Null values are not supported.

FloatArrayType

public static final 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 NavType<Float> FloatType

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

Null values are not supported.

IntArrayType

public static final 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 NavType<Integer> IntType

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

Null values are not supported.

LongArrayType

public static final 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 NavType<Long> LongType

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 NavType<Integer> ReferenceType

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 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 NavType<String> StringType

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

Null values are supported.

Public methods

fromArgType

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

Parse an argType string into a NavType.

Parameters
type String: argType string, usually parsed from the Navigation XML file

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

Returns
NavType<?> a NavType representing the type indicated by the argType string. Defaults to StringType for null.

get

public abstract T get (Bundle bundle,
                String key)

Get a value of this type from the bundle

Parameters
bundle Bundle: bundle to get value from

key String: bundle key

Returns
T value of this type

getName

public abstract String getName ()

Returns the name of this type.

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

Returns
String name of this type

isNullableAllowed

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

public abstract T parseValue (String value)

Parse a value of this type from a String.

Parameters
value String: string representation of a value of this type

Returns
T parsed value of the type represented by this NavType

Throws
IllegalArgumentException if value cannot be parsed into this type

put

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

Put a value of this type in he bundle

Parameters
bundle Bundle: bundle to put value in

key String: bundle key

value T: value of this type

toString

public String toString ()

Returns
String