Data

public final class Data
extends Object

java.lang.Object
   ↳ androidx.work.Data


A persistable set of key/value pairs which are used as inputs and outputs for ListenableWorkers. Keys are Strings, and values can be Strings, primitive types, or their array variants.

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

class Data.Builder

A builder for Data objects. 

Constants

int MAX_DATA_BYTES

The maximum number of bytes for Data when it is serialized (converted to a byte array).

Fields

public static final Data EMPTY

An empty Data object with no elements.

Public constructors

Data(Data other)

Public methods

boolean equals(Object o)
static Data fromByteArray(byte[] bytes)

Converts a byte array to Data.

boolean getBoolean(String key, boolean defaultValue)

Gets the boolean value for the given key.

boolean[] getBooleanArray(String key)

Gets the boolean array value for the given key.

byte getByte(String key, byte defaultValue)

Gets the byte value for the given key.

byte[] getByteArray(String key)

Gets the byte array value for the given key.

double getDouble(String key, double defaultValue)

Gets the double value for the given key.

double[] getDoubleArray(String key)

Gets the double array value for the given key.

float getFloat(String key, float defaultValue)

Gets the float value for the given key.

float[] getFloatArray(String key)

Gets the float array value for the given key.

int getInt(String key, int defaultValue)

Gets the integer value for the given key.

int[] getIntArray(String key)

Gets the integer array value for the given key.

Map<String, Object> getKeyValueMap()

Gets all the values in this Data object.

long getLong(String key, long defaultValue)

Gets the long value for the given key.

long[] getLongArray(String key)

Gets the long array value for the given key.

String getString(String key)

Gets the String value for the given key.

String[] getStringArray(String key)

Gets the String array value for the given key.

<T> boolean hasKeyWithValueOfType(String key, Class<T> klass)

Returns true if the instance of Data has a non-null value corresponding to the given String key with the expected type of T.

int hashCode()
byte[] toByteArray()

Converts this Data to a byte array suitable for sending to other processes in your application.

String toString()

Inherited methods

Constants

MAX_DATA_BYTES

public static final int MAX_DATA_BYTES

The maximum number of bytes for Data when it is serialized (converted to a byte array). Please see the class-level Javadoc for more information.

Constant Value: 10240 (0x00002800)

Fields

EMPTY

public static final Data EMPTY

An empty Data object with no elements.

Public constructors

Data

public Data (Data other)

Parameters
other Data

Public methods

equals

public boolean equals (Object o)

Parameters
o Object

Returns
boolean

fromByteArray

public static Dat