Module: Toybox.Application.Storage

Overview

The Storage module provides persistent storage to applications.

Storage provides access to persistent disk storage.

Since:

API Level 2.4.0

Instance Method Summary collapse

Instance Method Details

clearValues() as Void

Clear the object store for the application.

Since:

API Level 2.4.0

Throws:

deleteValue(key as Application.PropertyKeyType) as Void

Delete the given key from the object store.

Parameters:

See Also:

Since:

API Level 2.4.0

Throws:

getValue(key as Application.PropertyKeyType) as Application.PropertyValueType

Get the data associated with a given key from the object store.

Keys can be of the following types:

Values must first be set with setValue() before they are can be obtained with getValue.

Note:

Symbols can change from build to build and are not to be used for for Keys or Values

Parameters:

  • key(Lang.Object)

    The key of the value to retrieve from the object store (cannot be a Symbol)

Returns:

  • Lang.Object

    The content associated with the key, or null if the key is not in the object store

See Also:

Since:

API Level 2.4.0

Throws:

setValue(key as Application.PropertyKeyType, value as Application.PropertyValueType) as Void

Store the given data in the object.

Keys can be of the following types:

Values can be of the following types:

Values can also be of type Array or Dictionary containing the above listed types, excluding BitmapResource and AnimationResource. There is a limit on the size of the Object Store that can vary between devices. If you reach this limit, the value will not be saved and an exception will be thrown. Also, values are limited to 32 KB in size.

Note:

Symbols can change from build to build and are not to be used for for Keys or Values

Parameters:

  • key(Lang.Object)

    The key used to store and retrieve the value from the object store (cannot be a Symbol)

  • value(Lang.Object)

    The value to put into the object store

Example:

using Toybox.Application.Storage;

Storage.setValue("number", 2);               // set value for "number" key
Storage.setValue("float", 3.14);             // set value for "float" key
Storage.setValue("string", "Hello World!");  // set value for "string" key
Storage.setValue("boolean", true);           // set value for "boolean" key

var int = Storage.getValue("number");          // get value for "number" key
var float = Storage.getValue("float");         // get value for "float" key
var string = Storage.getValue("string");       // get value for "string" key
var boolean = Storage.getValue("boolean");     // get value for "boolean" key

See Also:

Since:

API Level 2.4.0

Throws:


Generated Apr 17, 2024 9:40:36 AM