@@ -625,7 +625,7 @@ Subscribes to the wallpaper color change event.
...
@@ -625,7 +625,7 @@ Subscribes to the wallpaper color change event.
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the event to subscribe to. The value **'colorChange'** indicates subscribing to the wallpaper color change event.|
| type | string | Yes| Type of the event to subscribe to. The value **'colorChange'** indicates subscribing to the wallpaper color change event.|
| callback | function | Yes| Callback triggered when the wallpaper color changes. The wallpaper type and main colors are returned.<br>- colors<br> Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolordeprecated).<br>- wallpaperType<br> Wallpaper type.|
| callback | function | Yes| Callback triggered when the wallpaper color changes. The wallpaper type and main colors are returned.<br>- **colors**: main color information of the wallpaper. For details, see [RgbaColor](#rgbacolordeprecated).<br>- **wallpaperType**: wallpaper type. |
**Example**
**Example**
...
@@ -657,7 +657,7 @@ Unsubscribes from the wallpaper color change event.
...
@@ -657,7 +657,7 @@ Unsubscribes from the wallpaper color change event.
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the event to unsubscribe from. The value **'colorChange'** indicates unsubscribing from the wallpaper color change event.|
| type | string | Yes| Type of the event to unsubscribe from. The value **'colorChange'** indicates unsubscribing from the wallpaper color change event.|
| callback | function | No| Callback for the wallpaper color change event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.<br>- colors<br> Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolordeprecated).<br>- wallpaperType<br> Wallpaper type.|
| callback | function | No| Callback used for unsubscription. If this parameter is not set, this API unsubscribes from all callbacks of the specified event type.<br>- **colors**: main color information of the wallpaper. For details, see [RgbaColor](#rgbacolordeprecated).<br>- **wallpaperType**: wallpaper type. |
# State Management with Application-level Variables
# State Management with Application-level Variables
The state management module provides APIs for data storage, persistent data management, **Ability** data storage, and environment status required by applications.
> **NOTE**
The state management module provides data storage, persistent data management, UIAbility data storage, and environment state required by applications.
>**NOTE**
>
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The meanings of T and S in this topic are as follows:
| Type | Description |
| ---- | -------------------------------------- |
| T | Class, number, boolean, string, and arras of these types.|
| S | number, boolean, string. |
## AppStorage
## AppStorage
### Link
Link(propName: string): any
For details about how to use AppStorage on the UI, see [AppStorage: Application-wide UI State Storage](../../quick-start/arkts-appstorage.md).
Establishes two-way data binding with the given attribute (specified by **propName**) in AppStorage. If the given attribute exists in AppStorage, the two-way bound data of the attribute in AppStorage is returned.
Any update of the data is synchronized back to AppStorage, which then synchronizes the update to all data and custom components bound to the attribute.
If the given attribute does not exist in AppStorage, **undefined** is returned.
Establishes two-way data binding between an attribute and this **LocalStorage** instance.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------- |
| -------- | ------ | ---- | ---------------- |
| propName | string | Yes | Name of the target attribute.|
| propName | string | Yes | Attribute name in AppStorage.|
| @Link | Returns two-way binding to this attribute if there is data with a given key. This means that attribute changes made by a variable or component will be synchronized to the **AppStorage**, and attribute changes made through the **AppStorage** will be synchronized to the variable or component.|
| SubscribedAbstractProperty<T> | Returns two-way bound data if specified attribute exists in AppStorage; returns **undefined** otherwise.|
Works in a way similar to the **Link** API. If the current key is stored in the **AppStorage**, the value corresponding to the key is returned. If the key has not been created, a **Link** instance corresponding to the default value is created and returned.
Works in a way similar to the **Link** API. If the given attribute exists in AppStorage, the two-way bound data of the attribute in AppStorage is returned. If the given attribute does not exist, it is created and initialized with <bclass="+ topic/ph hi-d/b "id="b537113298389">defaultValue</b> in AppStorage, and two-way bound data is returned.
| @Link | Returns the value corresponding to the key if the current key is stored in the **AppStorage**; creates and returns a **Link** instance corresponding to the default value if the key has not been created.|
| SubscribedAbstractProperty<T> | Instance of **SubscribedAbstractProperty<T>** and two-way bound data of the given attribute in AppStorage|
Establishes one-way data binding with an attribute to update its status.
Establishes one-way data binding with the given attribute (specified by **propName**) in AppStorage. If the given attribute exists in AppStorage, the one-way bound data of the attribute in AppStorage is returned. If the given attribute does not exist in AppStorage, **undefined** is returned. Updates of the one-way bound data are not synchronized back to AppStorage.
>**NOTE**
>
>Prop supports only simple types.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------- |
| -------- | ------ | ---- | ---------------- |
| propName | string | Yes | Target key.|
| propName | string | Yes | Attribute name in AppStorage.|
| @Prop | Returns one-way binding to an attribute with a given key if the attribute exists; returns **undefined** otherwise. One-way binding means that attribute changes made through the **AppStorage** will be synchronized to the variable or component, but attribute changes made by the variable or component will not be synchronized to the **AppStorage**. This API returns immutable variables and is applicable to mutable and immutable state variables alike.|
| SubscribedAbstractProperty<T> | Returns one-way bound data if specified attribute exists in AppStorage; returns **undefined** otherwise.|
Works in a way similar to the **Prop** API. If the given attribute exists in AppStorage, the one-way bound data of the attribute in AppStorage is returned. If the given attribute does not exist, it is created and initialized with **defaultValue** in AppStorage, and one-way bound data is returned.
Works in a way similar to the **Prop** API. If the current key is stored in the **AppStorage**, the value corresponding to the key is returned. If the key has not been created, a **Prop** instance corresponding to the default value is created and returned.
| @Prop | Returns the value corresponding to the key if the current key is stored in the **AppStorage**; creates and returns a **Prop** instance corresponding to the default value otherwise.|
| SubscribedAbstractProperty<T> | Instance of **SubscribedAbstractProperty<T>**.|
| boolean | Returns **true** and the value if the key exists; returns **false** otherwise.|
| boolean | Returns **true** if the operation is successful; return **false** if the attribute with the specified attribute name does not exist in AppStorage, or the value to set is **undefined** or **null**. |
Sets a new value for the attribute with the specified attribute name in AppStorage or, if the attribute does not exist, creates one with the specified attribute name and default value.
| boolean | Updates the value of the attribute and returns **true** if an attribute that has the same name as the specified key exists; creates an attribute with the specified value as its default value and returns **false** otherwise. **undefined** and **null** are not allowed to return **true**.|
Deletes the attribute with the specified attribute name from AppStorage
under the prerequisite that the attribute does not have a subscriber. If there is a subscriber, **false** is returned. If the deletion is successful, **true** is returned.
Deletes the key-value pair that matches the specified key.
The subscribers of the attribute are attributes with the same name bound to APIs such as **Link** and **Prop**, **\@StorageLink('propName')**, and **\@StorageProp('propName')**. This means that if **\@StorageLink('propName')** and **\@StorageProp('propName')** are used in a custom component or if there is still a **SubscribedAbstractProperty** instance in sync with the attribute, the attribute cannot be deleted from AppStorage.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------ |
| -------- | ------ | ---- | ---------------- |
| propName | string | Yes | Key of the target key-value pair.|
| propName | string | Yes | Attribute name in AppStorage.|
Deletes all attributes from AppStorage under the prerequisite that none of the attributes has a subscriber. If any of the attributes has a subscriber, **false** is returned. If the deletion is successful, **true** is returned.
This API is deprecated since API version 9. You are advised to use [Clear](#clear) instead.
For details about the subscriber, see [Delete](#delete10).
| boolean | Returns **true** if all attributes are deleted; returns **false** if any of the attributes is being referenced by a state variable.|
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
```ts
```ts
letsimple=AppStorage.staticClear()
AppStorage.setOrCreate('PropA',47);
letres:boolean=AppStorage.clear();// true, there are no subscribers
```
```
### Clear<sup>9+</sup>
Clear(): boolean
### size<sup>10+</sup>
Deletes all attributes.
static size(): number
Obtains the number of attributes in AppStorage.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | --------------------------------- |
| ------ | ------------------- |
| boolean | Returns **true** if all attributes are deleted; returns **false** if any of the attributes is being referenced by a state variable.|
| number | Number of attributes in AppStorage.|
```ts
```ts
letsimple=AppStorage.Clear()
AppStorage.setOrCreate('PropB',48);
letres:number=AppStorage.size();// 1
```
```
### IsMutable
IsMutable(propName: string): boolean
### Link<sup>(deprecated)</sup>
static Link(propName: string): any
Establishes two-way data binding with the given attribute (specified by **propName**) in AppStorage. If the given attribute exists in AppStorage, the two-way bound data of the attribute in AppStorage is returned.
Any update of the data is synchronized back to AppStorage, which then synchronizes the update to all data and custom components bound to the attribute.
If the given attribute does not exist in AppStorage, **undefined** is returned.
This API is deprecated since API version 10. You are advised to use [link10+](#link10) instead.
Checks whether an attribute exists and can be changed.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | ------ | :--- | ------------ |
| -------- | ------ | ---- | ---------------- |
| propName | string | Yes | Key of the target attribute.|
| propName | string | Yes | Attribute name in AppStorage.|
Works in a way similar to the **Link** API. If the given attribute exists in AppStorage, the two-way bound data of the attribute in AppStorage is returned. If the given attribute does not exist, it is created and initialized with <bclass="+ topic/ph hi-d/b "id="b537113298389">defaultValue</b> in AppStorage, and two-way bound data is returned.
Obtains the number of existing key-value pairs.
This API is deprecated since API version 10. You are advised to use [setAndLink10+](#setandlink10) instead.
| number | Returns the number of key-value pairs.|
| SubscribedAbstractProperty<T> | Instance of **SubscribedAbstractProperty<T>** and two-way bound data of the given attribute in AppStorage|
Establishes one-way data binding with the given attribute (specified by **propName**) in AppStorage. If the given attribute exists in AppStorage, the one-way bound data of the attribute in AppStorage is returned. If the given attribute does not exist in AppStorage, **undefined** is returned. Updates of the one-way bound data are not synchronized back to AppStorage.
Creates and initializes a **LocalStorage** object.
>**NOTE**
>
>Prop supports only simple types.
>
>This API is deprecated since API version 10. You are advised to use [prop10+](#prop10) instead.
Works in a way similar to the **Prop** API. If the given attribute exists in AppStorage, the one-way bound data of the attribute in AppStorage is returned. If the given attribute does not exist, it is created and initialized with **defaultValue** in AppStorage, and one-way bound data is returned.
This API can be used only in the stage model.
This API is deprecated since API version 10. You are advised to use [setAndProp10+](#setandprop10) instead.
| boolean | Returns **true** and the value if the key exists; returns **false** otherwise.|
| boolean | Returns **true** if the operation is successful; return **false** if the attribute with the specified attribute name does not exist in AppStorage, or the value to set is **undefined** or **null**. |
Creates or updates the value of the specified key.
Sets a new value for the attribute with the specified attribute name in AppStorage or, if the attribute does not exist, creates one with the specified attribute name and default value.
This API is deprecated since API version 10. You are advised to use [setOrCreate10+](#setorcreate10) instead.
| boolean | Updates the value of the attribute and returns **true** if an attribute that has the same name as the specified key exists; creates an attribute with the specified value as its default value and returns false otherwise. **undefined** and **null** are not allowed.|
```ts
```ts
letstorage=newLocalStorage()
AppStorage.SetOrCreate('simpleProp',121);
storage.setOrCreate('storageSimpleProp',121)
```
```
### link<sup>9+</sup>
link\<T>(propName: string): T
### Delete<sup>(deprecated)</sup>
Establishes two-way data binding between an attribute and this **LocalStorage** instance.
static Delete(propName: string): boolean
Deletes the attribute with the specified attribute name from AppStorage
under the prerequisite that the attribute does not have a subscriber. If there is a subscriber, **false** is returned. If the deletion is successful, **true** is returned.
The subscribers of the attribute are attributes with the same name bound to APIs such as **Link** and **Prop**, **\@StorageLink('propName')**, and **\@StorageProp('propName')**. This means that if **\@StorageLink('propName')** and **\@StorageProp('propName')** are used in a custom component or if there is still a **SubscribedAbstractProperty** instance in sync with the attribute, the attribute cannot be deleted from AppStorage.
This API is deprecated since API version 10. You are advised to use [delete10+](#delete10) instead.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------- |
| -------- | ------ | ---- | ---------------- |
| propName | string | Yes | Name of the target attribute.|
| propName | string | Yes | Attribute name in AppStorage.|
| T | Returns two-way binding to this attribute if there is data with a given key. This means that attribute changes made by a variable or component will be synchronized to the **LocalStorage**, and attribute changes made through the **LocalStorage** will be synchronized to the variable or component. returns **undefined** if the attribute with the given key does not exist.|
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
```ts
```ts
letstorage=newLocalStorage()
AppStorage.SetOrCreate('PropA',47);
letlocalStorage=storage.link('storageSimpleProp')
AppStorage.Link('PropA');
letres:boolean=AppStorage.Delete('PropA');// false, PropA still has a subscriber
AppStorage.SetOrCreate('PropB',48);
letres1:boolean=AppStorage.Delete('PropB');// true, PropB is deleted from AppStorage successfully
```
```
### setAndLink<sup>9+</sup>
setAndLink\<T>(propName: string, defaultValue: T): T
### Keys<sup>(deprecated)</sup>
Works in a way similar to the **Link** API.
static Keys(): IterableIterator<string>
**Parameters**
Obtains all attribute names in AppStorage.
| Name | Type | Mandatory | Description |
This API is deprecated since API version 10. You are advised to use [keys10+](#keys10) instead.
| ------------ | ------ | ---- | ----------- |
| propName | string | Yes | Target key.|
| defaultValue | T | Yes | Default value to set. |
| @Link | Returns the value corresponding to the key if the current key is stored in the **LocalStorage**; creates and returns a **Link** instance corresponding to the default value if the key has not been created.|
| IterableIterator<string> | All attribute names in AppStorage.|
| @Prop | Returns one-way binding to an attribute with a given key if the attribute exists; returns **undefined** otherwise. One-way binding means that attribute changes made through the **LocalStorage** will be synchronized to the variable or component, but attribute changes made by the variable or component will not be synchronized to the **LocalStorage**. This API returns immutable variables and is applicable to mutable and immutable state variables alike. |
| boolean | Returns **true** if all attributes are deleted; returns **false** if any of the attributes is being referenced by a state variable.|
```ts
```ts
letstorage=newLocalStorage()
letsimple=AppStorage.staticClear();
letlocalStorage=storage.prop('storageSimpleProp')
```
```
### setAndProp<sup>9+</sup>
setAndProp\<T>(propName: string, defaultValue: T): T
### Clear<sup>(deprecated)</sup>
Works in a way similar to the **Prop** API.
static Clear(): boolean
**Parameters**
Deletes all attributes from AppStorage under the prerequisite that none of the attributes has a subscriber. If any of the attributes has a subscriber, **false** is returned. If the deletion is successful, **true** is returned.
| Name | Type | Mandatory | Description |
For details about the subscriber, see [Delete](#deletedeprecated).
| ------------ | ------ | ---- | -------------- |
| propName | string | Yes | Key of the target key-value pair.|
This API is deprecated since API version 10. You are advised to use [clear10+](#clear10) instead.
| defaultValue | T | Yes | Default value to set. |
| @Prop | Returns the value corresponding to the given key if the key is stored in the **LocalStorage**; creates and returns a **Prop** instance corresponding to the default value if the key has not been created.|
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
For details about how to use **getShared**, see [Sharing a LocalStorage Instance from UIAbility to One or More Pages](../../quick-start/arkts-localstorage.md#sharing-a-localstorage-instance-from-uiability-to-one-or-more-pages).
| boolean | Returns **true** if the operation is successful; return **false** if the attribute with the specified attribute name does not exist in LocalStorage, or the value to set is **undefined** or **null**. |
Sets a new value for the attribute with the specified attribute name in LocalStorage or, if the attribute does not exist, creates one with the specified attribute name and default value.
Changes the attributes that match the specified keys to persistent data in the **AppStorage**.
Since API version 9, this API is supported in ArkTS widgets.
| boolean | Returns **false** if **newValue** is set to **undefined** or **null**.<br>Updates the target attribute with the new value and returns **true** if the attribute exists in LocalStorage.<br>Creates an attribute with the specified attribute name and default value if the attribute does not exist in LocalStorage.|
Establishes two-way data binding with the given attribute in this **LocalStorage** instance. If the given attribute exists, the two-way bound data of the attribute in LocalStorage is returned.
| Type | Description |
Any update of the data is synchronized back to LocalStorage, which then synchronizes the update to all data and custom components bound to the attribute.
| -------------- | ------------- |
| Array\<string> | Returns the flags of all persistent attributes.|
```ts
If the given attribute does not exist in LocalStorage, **undefined** is returned.
letsimple=PersistentStorage.Keys()
```
> **NOTE**
Since API version 9, this API is supported in ArkTS widgets.
>
> - When using **PersistProp**, ensure that the input key exists in the **AppStorage**.
>
> - **DeleteProp** takes effect only for the data that has been linked during the current startup.
## Environment
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------ |
| propName | string | Yes | Attribute name in LocalStorage.|
| SubscribedAbstractProperty<T> | Returns the **SubscribedAbstractProperty<T>** instance if the given attribute exists in AppStorage; returns **undefined** otherwise.|
Binds this system attribute to the **AppStorage**. You are advised to use this API during application startup. If the attribute already exists in the **AppStorage**, **false** is returned. Do not use the variables in the **AppStorage**. Instead, call this API to bind environment variables.
Works in a way similar to the **Link** API. If the given attribute exists in LocalStorage, the two-way bound data of the attribute in LocalStorage is returned. If the given attribute does not exist, it is created and initialized with **defaultValue** in LocalStorage, and two-way bound data is returned.
Since API version 9, this API is supported in ArkTS widgets.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description | Description |
| boolean | Returns whether the attribute exists in the **AppStorage**.|
| SubscribedAbstractProperty<T> | Returns the **SubscribedAbstractProperty<T>** instance if the given attribute exists in AppStorage; returns **undefined** otherwise.|
| accessibilityEnabled | string | Whether to enable accessibility. |
| colorMode | ColorMode | Color mode. The options are as follows:<br>- **ColorMode.LIGHT**: light mode.<br>- **ColorMode.DARK**: dark mode.|
| fontScale | number | Font scale. |
| fontWeightScale | number | Font weight scale. |
| layoutDirection | LayoutDirection | Layout direction. The options are as follows:<br>- **LayoutDirection.LTR**: The direction is from left to right.<br>- **LayoutDirection.RTL**: The direction is from right to left.|
| languageCode | string | Current system language. The value is in lowercase, for example, **zh**. |
Associates this system item array with the **AppStorage**.
Establishes one-way data binding with the given attribute in this **LocalStorage** instance. If the given attribute exists, the one-way bound data of the attribute in LocalStorage is returned. If the given attribute does not exist in LocalStorage, **undefined** is returned. Updates of the one-way bound data are not synchronized back to LocalStorage.
Since API version 9, this API is supported in ArkTS widgets.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description | Description |
| SubscribedAbstractProperty<S> | Returns the **SubscribedAbstractProperty<S>** instance if the given attribute exists in LocalStorage; returns **undefined** otherwise.|
Establishes one-way data binding with the given attribute in this **LocalStorage** instance. If the given attribute exists, the one-way bound data of the attribute in LocalStorage is returned. If the given attribute does not exist, it is created and initialized with **defaultValue** in LocalStorage, and one-way bound data is returned.
Returns an array of associated system attributes.
Since API version 9, this API is supported in ArkTS widgets.
| Array\<string> | Returns an array of associated system attributes.|
| SubscribedAbstractProperty<S> | Instance of **SubscribedAbstractProperty<T>** and one-way bound data of the given attribute in LocalStorage.|
Deletes the attribute with the specified attribute name from LocalStorage under the prerequisite that the attribute does not have a subscriber. If the deletion is successful, **true** is returned.
The subscribers of the attribute are attributes with the same name bound to the **Link** and **Prop** APIs, **\@LocalStorageLink('propName')**, and **\@LocalStorageProp('propName')**. This means that if **\@LocalStorageLink('propName')** and **\@LocalStorageProp('propName')** are used in a custom component or if there is still a **SubscribedAbstractProperty** instance (return type of the **link** and **prop** APIs) in sync with the attribute, the attribute cannot be deleted from LocalStorage.
Since API version 9, this API is supported in ArkTS widgets.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------ |
| propName | string | Yes | Attribute name in LocalStorage.|
Deletes all attributes from LocalStorage under the prerequisite that none of the attributes has a subscriber. If any of the attributes has a subscriber, **false** is returned. If the deletion is successful, **true** is returned.
Since API version 9, this API is supported in ArkTS widgets.
For details about how to use PersistentStorage on the UI, see [PersistentStorage: Application State Persistence](../../quick-start/arkts-persiststorage.md).
| defaultValue | number\|string\|boolean | Yes | Default value used to initialize the created attribute. The value cannot be **undefined** or **null**.|
Persists the attribute with the specified key in AppStorage to a file. This API is usually called before access to AppStorage.
The sequence of determining the type and value of an attribute is as follows:
1. If the PersistentStorage file contains the attribute with the specified key, an attribute with the key as the name is created in AppStorage and initialized with the attribute of the key found in PersistentStorage.
2. If the attribute with the specified key is not found in the PersistentStorage file, AppStorage is searched for the attribute corresponding to the key. If the matching attribute is found, it is persisted.
3. If no matching attribute is found in AppStorage, it is created in AppStorage, initialized with the value of **defaultValue**, and persisted.
According to the preceding initialization process, if AppStorage contains the matching attribute, the value of this attribute is used to overwrite the value in the PersistentStorage file. Because AppStorage stores data in the memory, the attribute value becomes impersistent.
| defaultValue | T | Yes | Default value used to initialize the created attribute. The value cannot be **undefined** or **null**.|
**Example:**
For details about how to use persistProp, see [Accessing PersistentStorage Initialized Attribute from AppStorage](../../quick-start/arkts-persiststorage.md#accessing-persistentstorage-initialized-attribute-from-appstorage).
### deleteProp<sup>10+</sup>
static deleteProp(key: string): void
Performs the reverse operation of **PersistProp**. Specifically, this API deletes the attribute corresponding to the key from PersistentStorage. Subsequent AppStorage operations do not affect data in PersistentStorage.
Works in a way similar to the **PersistProp** API, with the difference that it allows for persistence in batches and is therefore ideal for initialization during application startup.
Persists the attribute with the specified key in AppStorage to a file. This API is usually called before access to AppStorage.
The sequence of determining the type and value of an attribute is as follows:
1. If the PersistentStorage file contains the attribute with the specified key, an attribute with the key as the name is created in AppStorage and initialized with the attribute of the key found in PersistentStorage.
2. If the attribute with the specified key is not found in the PersistentStorage file, AppStorage is searched for the attribute corresponding to the key. If the matching attribute is found, it is persisted.
3. If no matching attribute is found in AppStorage, it is created in AppStorage, initialized with the value of **defaultValue**, and persisted.
According to the preceding initialization process, if AppStorage contains the matching attribute, the value of this attribute is used to overwrite the value in the PersistentStorage file. Because AppStorage stores data in the memory, the attribute value becomes impersistent.
This API is deprecated since API version 10. You are advised to use [persistProp10+](#persistprop10) instead.
| defaultValue | T | Yes | Default value used to initialize the created attribute. The value cannot be **undefined** or **null**.|
**Example:**
```ts
PersistentStorage.PersistProp('highScore','0');
```
### DeleteProp<sup>(deprecated)</sup>
static DeleteProp(key: string): void
Performs the reverse operation of **PersistProp**. Specifically, this API deletes the attribute corresponding to the key from PersistentStorage. Subsequent AppStorage operations do not affect data in PersistentStorage.
This API is deprecated since API version 10. You are advised to use [deleteProp10+](#deleteprop10) instead.
Works in a way similar to the **PersistProp** API, with the difference that it allows for persistence in batches and is therefore ideal for initialization during application startup.
This API is deprecated since API version 10. You are advised to use [persistProps10+](#persistprops10) instead.
| properties | {key: string, defaultValue: any}[] | Yes | Array of attributes to persist.<br>**key**: attribute name.<br>**defaultValue**: default value. The rules are the same as those of **PersistProp**.|
| key | string | Yes | Environment variable name. For details about the value range, see [Built-in Environment Variables](#built-in-environment-variables).|
| defaultValue | number\|string\|boolean | Yes | Default value used if the value of the environment variable key is not found in AppStorage.|
Saves the built-in environment variable key in environment to AppStorage. If the value of the environment variable key is not found in AppStorage, the default value is used. If the value is successfully saved, **true** is returned. If the value of the environment variable key is found in AppStorage, **false** is returned.
You are advised to call this API when the application is started.
It is incorrect to use AppStorage to read environment variables without invoking **EnvProp**.
| key | string | Yes | Environment variable name. For details about the value range, see [Built-in Environment Variables](#built-in-environment-variables). |
| value | S | Yes | Default value used if the value of the environment variable key is not found in AppStorage.|
| boolean | Returns **false** if the attribute corresponding to the key exists in AppStorage; returns **false** otherwise.|
**Example:**
For details about how to use **envProp**, see [Accessing Environment Parameters from UI](../../quick-start/arkts-environment.md#accessing-environment-parameters-from-ui).
### envProps<sup>10+</sup>
static envProps(props: EnvPropsOptions[]): void
Works in a way similar to the **EnvProp** API, with the difference that it allows for initialization of multiple attributes in batches. You are advised to call this API during application startup to save system environment variables to AppStorage in batches.
Saves the built-in environment variable key in environment to AppStorage. If the value of the environment variable key is not found in AppStorage, the default value is used. If the value is successfully saved, **true** is returned. If the value of the environment variable key is found in AppStorage, **false** is returned.
You are advised to call this API when the application is started.
It is incorrect to use AppStorage to read environment variables without invoking **EnvProp**.
This API is deprecated since API version 10. You are advised to use [envProp10+](#envprop10) instead.
| key | string | Yes | Environment variable name. For details about the value range, see [Built-in Environment Variables](#built-in-environment-variables). |
| value | S | Yes | Default value used if the value of the environment variable key is not found in AppStorage.|
Works in a way similar to the **EnvProp** API, with the difference that it allows for initialization of multiple attributes in batches. You are advised to call this API during application startup to save system environment variables to AppStorage in batches.
This API is deprecated since API version 10. You are advised to use [envProps10+](#envprops10) instead.
| accessibilityEnabled | string | Whether to enable accessibility. |
| colorMode | ColorMode | Color mode. The options are as follows:<br>- **ColorMode.LIGHT**: light mode.<br>- **ColorMode.DARK**: dark mode.|
| fontScale | number | Font scale. |
| fontWeightScale | number | Font weight scale. |
| layoutDirection | LayoutDirection | Layout direction. The options are as follows:<br>- **LayoutDirection.LTR**: from left to right.<br>- **LayoutDirection.RTL**: from right to left.|
| languageCode | string | Current system language. The value is in lowercase, for example, **zh**. |