Android 12 Developer Preview is here! Try it out, and give us your feedback!

NavType

abstract class NavType<T : Any!>
kotlin.Any
   ↳ androidx.navigation.NavType

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

EnumType is used for NavArguments holding enum values.

ParcelableArrayType is used for NavArguments which hold arrays of Parcelables.

ParcelableType is used for passing Parcelables in NavArguments.

SerializableArrayType is used for NavArguments that hold arrays of Serializables.

open

SerializableType is used for Serializable NavArguments.

Public methods
open static NavType<*>
fromArgType(@Nullable type: String?, @Nullable packageName: String?)

Parse an argType string into a NavType.

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

Get a value of this type from the bundle

abstract String

Returns the name of this type.

open Boolean

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

abstract T
parseValue(@NonNull value: String)

Parse a value of this type from a String.

abstract Unit
put(@NonNull bundle: Bundle, @NonNull key: String, @Nullable value: T?)

Put a value of this type in he bundle

open String

Properties
static NavType<BooleanArray!>

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

static NavType<Boolean!>

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

static NavType<FloatArray!>

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

static NavType<Float!>

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

static NavType<IntArray!>

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

static NavType<Int!>

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

static NavType<LongArray!>

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

static NavType<Long!>

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

static NavType<Int!>

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

static NavType<Array<String!>!>

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

static NavType<String!>

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

Public methods

fromArgType

@NonNull open static fun fromArgType(
    @Nullable type: String?,
    @Nullable packageName: String?
): NavType<*>

Parse an argType string into a NavType.

Parameters