Fundamental Concepts
ApplicationSettings
Persist data locally on the device storage
ApplicationSettings
allows you to store and retrieve data from the device local storage via getters and setters for storing and retrieving different data types. Use the appropriate setter to avoid errors.
How to use ApplicationSettings
Store a string value
To store a string value, use the setString method:
ApplicationSettings.setString('username', 'Wolfgang')
TIP
You can use this method with the JSON.stringify()
(as shown in the saveObjectAsString
method in the StackBlitz demo app at the link above) to store an object or an array as a string. Then, use JSON.parse()
to convert the result of getString() back to the object or array.
Store a boolean value
To store a boolean value, call the setBoolean method passing the key as the first argument and the value as second argument.
ApplicationSettings.setBoolean('isTurnedOn', true)
Store a numeric value
To store a number, use the setNumber() method:
ApplicationSettings.setNumber('locationX', 54.321)
ApplicationSettings API
setString()
ApplicationSettings.setString(key: string, value: string)
Stores a string value for the specified key.
getString()
ApplicationSettings.getString(key: string, deafaultValue?: string)
Gets a value (if existing) for a key as a String
object. A default value can be provided in case there is no existing value.
setNumber()
ApplicationSettings.setNumber(key: string, value: number)
Sets a Number
object for a key.
getNumber()
ApplicationSettings.getNumber(key: string, deafaultValue?: number)
Gets a value (if existing) for a key as a Number
object. A default value can be provided in case the value does not exist.
setBoolean()
ApplicationSettings.setBoolean(key: string, value: boolean)
Sets a boolean
for a key.
getBoolean()
ApplicationSettings.getBoolean(key: string, deafaultValue?: boolean)
Gets a value (if existing) for a key as a boolean
. A default value can be provided in case the value does not exist.value.
remove()
ApplicationSettings.remove(key: string)
Removes the key and its value from the device storage.
clear()
ApplicationSettings.clear()
Removes all values from the device storage.
getAllKeys()
ApplicationSettings.getAllKeys(): Array<string>
Returns an array of all stored keys or an empty array if no keys exist in the device storage.
API Reference(s)
- ApplicationSettings module
Native Component
Android
: SharedPreferencesiOS
: NSUserDefaults
- Previous
- Application
- Next
- Color