Data

class Data
kotlin.Any
   ↳ androidx.work.Data

Persistable set of key/value pairs which are passed as inputs and outputs for Workers. This is a lightweight container, and should not be considered your data store. As such, there is an enforced #MAX_DATA_BYTES limit on the serialized (byte array) size of the payloads. This class will throw IllegalStateExceptions if you try to serialize or deserialize past this limit.

Summary

Nested classes

A builder for Data.

Constants
static Int

Public methods
Int

Boolean
getBoolean(key: String!, defaultValue: Boolean)

Get the boolean value for the given key.

MutableMap<String!, Any!>!

Gets all the values in this Data object.

BooleanArray!

Get the boolean array value for the given key.

FloatArray!

Get the float array value for the given key.

Boolean
equals(other: Any?)

Int
getInt(key: String!, defaultValue: Int)

Get the integer value for the given key.

LongArray!

Get the long array value for the given key.

Long
getLong(key: String!, defaultValue: Long)

Get the long value for the given key.

DoubleArray!

Get the double array value for the given key.

Float
getFloat(key: String!, defaultValue: Float)

Get the float value for the given key.

IntArray!

Get the integer array value for the given key.

Int

String!
getString(key: String!, defaultValue: String!)

Get the String value for the given key.

Double
getDouble(key: String!, defaultValue: Double)

Get the double value for the given key.

Array<String!>!

Get the String array value for the given key.

static ByteArray!
toByteArray(data: Data!)

Converts Data to a byte array for persistent storage.

static Data!

Converts a byte array to Data.

Properties
static Data!

Constants

MAX_DATA_BYTES

static val MAX_DATA_BYTES: Int
Value: 10240

Public methods

hashCode

fun hashCode(): Int

getBoolean

fun getBoolean(key: String!, defaultValue: Boolean): Boolean

Get the boolean value for the given key.

Parameters
key String!: The key for the argument
defaultValue String!: The default value to return if the key is not found
Return
Boolean: The value specified by the key if it exists; the default value otherwise

getKeyValueMap

fun getKeyValueMap(): MutableMap<String!, Any!>!

Gets all the values in this Data object.

Return
MutableMap<String!, Any!>!: A Map of key-value pairs for this object; this Map is unmodifiable and should be used for reads only.

getBooleanArray

fun getBooleanArray(key: String!): BooleanArray!

Get the boolean array value for the given key.

Parameters
key String!: The key for the argument
Return
BooleanArray!: The value specified by the key if it exists; null otherwise

getFloatArray

fun getFloatArray(key: String!): FloatArray!

Get the float array value for the given key.

Parameters
key String!: The key for the argument
Return
FloatArray!: The value specified by the key if it exists; null otherwise

equals

fun equals(other: Any?): Boolean

getInt

fun getInt(key: String!, defaultValue: Int): Int

Get the integer value for the given key.

Parameters
key String!: The key for the argument
defaultValue String!: The default value to return if the key is not found
Return
Int: The value specified by the key if it exists; the default value otherwise

getLongArray

fun getLongArray(key: String!): LongArray!

Get the long array value for the given key.

Parameters
key String!: The key for the argument
Return
LongArray!: The value specified by the key if it exists; null otherwise

getLong

fun getLong(key: String!, defaultValue: Long): Long

Get the long value for the given key.

Parameters
key String!: The key for the argument
defaultValue String!: The default value to return if the key is not found
Return
Long: The value specified by the key if it exists; the default value otherwise

getDoubleArray

fun getDoubleArray(key: String!): DoubleArray!

Get the double array value for the given key.

Parameters
key String!: The key for the argument
Return
DoubleArray!: The value specified by the key if it exists; null otherwise

getFloat

fun getFloat(key: String!, defaultValue: Float): Float

Get the float value for the given key.

Parameters
key String!: The key for the argument
defaultValue String!: The default value to return if the key is not found
Return
Float: The value specified by the key if it exists; the default value otherwise

getIntArray

fun getIntArray(key: String!): IntArray!

Get the integer array value for the given key.

Parameters
key String!: The key for the argument
Return
IntArray!: The value specified by the key if it exists; null otherwise

size

fun size(): Int
Return
Int: The number of arguments

getString

fun getString(key: String!, defaultValue: String!): String!

Get the String value for the given key.

Parameters
key String!: The key for the argument
defaultValue String!: The default value to return if the key is not found
Return
String!: The value specified by the key if it exists; the default value otherwise

getDouble

fun getDouble(key: String!, defaultValue: Double): Double

Get the double value for the given key.

Parameters
key String!: The key for the argument
defaultValue String!: The default value to return if the key is not found
Return
Double: The value specified by the key if it exists; the default value otherwise

getStringArray

fun getStringArray(key: String!): Array<String!>!

Get the String array value for the given key.

Parameters
key String!: The key for the argument
Return
Array<String!>!: The value specified by the key if it exists; null otherwise

toByteArray

static fun toByteArray(data: Data!): ByteArray!

Converts Data to a byte array for persistent storage.

Parameters
data Data!: The Data object to convert
Return
ByteArray!: The byte array representation of the input
Exceptions
IllegalStateException if the serialized payload is bigger than #MAX_DATA_BYTES

fromByteArray

static fun fromByteArray(bytes: ByteArray!): Data!

Converts a byte array to Data.

Parameters
bytes ByteArray!: The byte array representation to convert
Return
Data!: An Data object built from the input
Exceptions
IllegalStateException if bytes is bigger than #MAX_DATA_BYTES

Properties

EMPTY

static val EMPTY: Data!