1e41f4b71Sopenharmony_ci# State Management with Application-level Variables 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciThe state management module provides data storage, persistent data management, UIAbility data storage, and environment state required by applications. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci>**NOTE** 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci>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. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciThe meanings of T and S in this topic are as follows: 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci| Type | Description | 16e41f4b71Sopenharmony_ci| ---- | -------------------------------------- | 17e41f4b71Sopenharmony_ci| T | Class, number, boolean, string, and arras of these types.| 18e41f4b71Sopenharmony_ci| S | number, boolean, string. | 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci## AppStorage 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciFor details about how to use AppStorage on the UI, see [AppStorage: Application-wide UI State Storage](../../../quick-start/arkts-appstorage.md). 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci### link<sup>10+</sup> 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_cistatic link<T>(propName: string): SubscribedAbstractProperty<T> 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ciEstablishes 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. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ciAny update of the data is synchronized back to AppStorage, which then synchronizes the update to all data and custom components bound to the attribute. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciIf the given attribute does not exist in AppStorage, **undefined** is returned. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**Parameters** 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 42e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 43e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**Return value** 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci| Type | Description | 48e41f4b71Sopenharmony_ci| ----------------------------------- | ------------------------------------------------------------ | 49e41f4b71Sopenharmony_ci| SubscribedAbstractProperty<T> | Returns two-way bound data if specified attribute exists in AppStorage; returns **undefined** otherwise.| 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci**Example** 52e41f4b71Sopenharmony_ci```ts 53e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 47); 54e41f4b71Sopenharmony_cilet linkToPropA1: SubscribedAbstractProperty<number> = AppStorage.link('PropA'); 55e41f4b71Sopenharmony_cilet linkToPropA2: SubscribedAbstractProperty<number> = AppStorage.link('PropA'); // linkToPropA2.get() == 47 56e41f4b71Sopenharmony_cilinkToPropA1.set(48); // Two-way synchronization: linkToPropA1.get() == linkToPropA2.get() == 48 57e41f4b71Sopenharmony_ci``` 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci### setAndLink<sup>10+</sup> 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_cistatic setAndLink<T>(propName: string, defaultValue: T): SubscribedAbstractProperty<T> 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ciWorks 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 **defaultValue** in AppStorage, and two-way bound data is returned. The value of **defaultValue** must be of the T type and cannot be **undefined** or **null**. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**Parameters** 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 71e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ------------------------------------------------------------ | 72e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage. | 73e41f4b71Sopenharmony_ci| defaultValue | T | Yes | Default value used to initialize the attribute with the specified attribute name in AppStorage. The value cannot be **undefined** or **null**.| 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci**Return value** 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci| Type | Description | 78e41f4b71Sopenharmony_ci| ----------------------------------- | ---------------------------------------- | 79e41f4b71Sopenharmony_ci| SubscribedAbstractProperty<T> | Instance of **SubscribedAbstractProperty<T>** and two-way bound data of the given attribute in AppStorage.| 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**Example** 82e41f4b71Sopenharmony_ci```ts 83e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 47); 84e41f4b71Sopenharmony_cilet link1: SubscribedAbstractProperty<number> = AppStorage.setAndLink('PropB', 49); // Create PropB 49 85e41f4b71Sopenharmony_cilet link2: SubscribedAbstractProperty<number> = AppStorage.setAndLink('PropA', 50); // PropA exists, remains 47 86e41f4b71Sopenharmony_ci``` 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci### prop<sup>10+</sup> 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_cistatic prop<T>(propName: string): SubscribedAbstractProperty<T> 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ciEstablishes 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. 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci**Parameters** 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 100e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 101e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci**Return value** 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci| Type | Description | 106e41f4b71Sopenharmony_ci| ----------------------------------- | ------------------------------------------------------------ | 107e41f4b71Sopenharmony_ci| SubscribedAbstractProperty<T> | Returns one-way bound data if specified attribute exists in AppStorage; returns **undefined** otherwise.| 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**Example** 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci```ts 112e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 47); 113e41f4b71Sopenharmony_cilet prop1: SubscribedAbstractProperty<number> = AppStorage.prop('PropA'); 114e41f4b71Sopenharmony_cilet prop2: SubscribedAbstractProperty<number> = AppStorage.prop('PropA'); 115e41f4b71Sopenharmony_ciprop1.set(1); // one-way sync: prop1.get()=1; but prop2.get() == 47 116e41f4b71Sopenharmony_ci``` 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci### setAndProp<sup>10+</sup> 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_cistatic setAndProp<T>(propName: string, defaultValue: T): SubscribedAbstractProperty<T> 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ciWorks 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. The value of **defaultValue** must be of the T type and cannot be **undefined** or **null**. 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**Parameters** 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 130e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ------------------------------------------------------------ | 131e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage. | 132e41f4b71Sopenharmony_ci| defaultValue | T | Yes | Default value used to initialize the attribute with the specified attribute name in AppStorage. The value cannot be **undefined** or **null**.| 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci**Return value** 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci| Type | Description | 137e41f4b71Sopenharmony_ci| ----------------------------------- | --------------------------------------- | 138e41f4b71Sopenharmony_ci| SubscribedAbstractProperty<T> | Instance of **SubscribedAbstractProperty<T>**.| 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**Example** 141e41f4b71Sopenharmony_ci```ts 142e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 47); 143e41f4b71Sopenharmony_cilet prop: SubscribedAbstractProperty<number> = AppStorage.setAndProp('PropB', 49); // PropA -> 47, PropB -> 49 144e41f4b71Sopenharmony_ci``` 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci### has<sup>10+</sup> 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_cistatic has(propName: string): boolean 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ciChecks whether the attribute with the specified attribute name exists in AppStorage. 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci**Parameters** 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 158e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 159e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**Return value** 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci| Type | Description | 164e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | 165e41f4b71Sopenharmony_ci| boolean | Returns **true** if the attribute with the specified attribute name exists in AppStorage; returns **false** otherwise.| 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci**Example** 168e41f4b71Sopenharmony_ci```ts 169e41f4b71Sopenharmony_ciAppStorage.has('simpleProp'); 170e41f4b71Sopenharmony_ci``` 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci### get<sup>10+</sup> 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_cistatic get<T>(propName: string): T | undefined 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ciObtains the attribute with the specified attribute name in AppStorage. If the attribute does not exist, **undefined** is returned. 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci**Parameters** 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 184e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 185e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci**Return value** 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci| Type | Description | 190e41f4b71Sopenharmony_ci| ------------------------ | ----------------------------------------------------------- | 191e41f4b71Sopenharmony_ci| T \| undefined | Returns the attribute with the specified attribute name in AppStorage; returns **undefined** if the attribute does not exist.| 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci**Example** 194e41f4b71Sopenharmony_ci```ts 195e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 47); 196e41f4b71Sopenharmony_cilet value: number = AppStorage.get('PropA') as number; // 47 197e41f4b71Sopenharmony_ci``` 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci### set<sup>10+</sup> 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_cistatic set<T>(propName: string, newValue: T): boolean 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ciSets the value for the attribute with the specified attribute name in AppStorage. If the value of **newValue** is the same as the value of the attribute with the specified attribute name, that is, no value needs to be assigned, the state variable will not instruct the UI to update the value of attribute. 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci**Parameters** 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 211e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------------- | 212e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage. | 213e41f4b71Sopenharmony_ci| newValue | T | Yes | Attribute value, which cannot be **undefined** or **null**.| 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci**Return value** 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci| Type | Description | 218e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 219e41f4b71Sopenharmony_ci| 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**. | 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci**Example** 222e41f4b71Sopenharmony_ci```ts 223e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 48); 224e41f4b71Sopenharmony_cilet res: boolean = AppStorage.set('PropA', 47) // true 225e41f4b71Sopenharmony_cilet res1: boolean = AppStorage.set('PropB', 47) // false 226e41f4b71Sopenharmony_ci``` 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci### setOrCreate<sup>10+</sup> 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_cistatic setOrCreate<T>(propName: string, newValue: T): void 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ciSets 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 the set value. 234e41f4b71Sopenharmony_ciIf the new value is the same as the existing value of the attribute with the specified attribute name, the state variable will not instruct the UI to update the value of the attribute. This **setOrCreate** method creates only one AppStorage key-value pair. To create multiple key-value pairs, call this method multiple times. 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ciThe value of **newValue** cannot be **undefined** or **null**. 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci**Parameters** 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 243e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------------- | 244e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage. | 245e41f4b71Sopenharmony_ci| newValue | T | Yes | Attribute value, which cannot be **undefined** or **null**.| 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci**Example** 248e41f4b71Sopenharmony_ci```ts 249e41f4b71Sopenharmony_ciAppStorage.setOrCreate('simpleProp', 121); 250e41f4b71Sopenharmony_ci``` 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci### delete<sup>10+</sup> 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_cistatic delete(propName: string): boolean 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ciDeletes 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. 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ciThe 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. 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci**Parameters** 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 266e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 267e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci**Return value** 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci| Type | Description | 272e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | 273e41f4b71Sopenharmony_ci| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci**Example** 276e41f4b71Sopenharmony_ci```ts 277e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 47); 278e41f4b71Sopenharmony_ciAppStorage.link<number>('PropA'); 279e41f4b71Sopenharmony_cilet res: boolean = AppStorage.delete('PropA'); // false, PropA still has a subscriber 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropB', 48); 282e41f4b71Sopenharmony_cilet res1: boolean = AppStorage.delete('PropB'); // true, PropB is deleted from AppStorage successfully 283e41f4b71Sopenharmony_ci``` 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci### keys<sup>10+</sup> 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_cistatic keys(): IterableIterator<string> 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ciObtains all attribute names in AppStorage. 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci**Return value** 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci| Type | Description | 297e41f4b71Sopenharmony_ci| ------------------------------ | ------------------ | 298e41f4b71Sopenharmony_ci| IterableIterator<string> | All attribute names in AppStorage.| 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci**Example** 301e41f4b71Sopenharmony_ci```ts 302e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropB', 48); 303e41f4b71Sopenharmony_cilet keys: IterableIterator<string> = AppStorage.keys(); 304e41f4b71Sopenharmony_ci``` 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci### clear<sup>10+</sup> 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_cistatic clear(): boolean 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ciDeletes all attributes from AppStorage under the prerequisite that none of the attributes has a subscriber. If any of the attributes has a subscriber, this API does not take effect and **false** is returned. If the deletion is successful, **true** is returned. 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ciFor details about the subscriber, see [delete](#delete10). 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci**Return value** 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ci| Type | Description | 320e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 321e41f4b71Sopenharmony_ci| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ci**Example** 324e41f4b71Sopenharmony_ci```ts 325e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 47); 326e41f4b71Sopenharmony_cilet res: boolean = AppStorage.clear(); // true, there are no subscribers 327e41f4b71Sopenharmony_ci``` 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci### size<sup>10+</sup> 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_cistatic size(): number 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ciObtains the number of attributes in AppStorage. 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci**Return value** 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci| Type | Description | 341e41f4b71Sopenharmony_ci| ------ | ------------------- | 342e41f4b71Sopenharmony_ci| number | Number of attributes in AppStorage.| 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci**Example** 345e41f4b71Sopenharmony_ci```ts 346e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropB', 48); 347e41f4b71Sopenharmony_cilet res: number = AppStorage.size(); // 1 348e41f4b71Sopenharmony_ci``` 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci### Link<sup>(deprecated)</sup> 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_cistatic Link(propName: string): any 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ciEstablishes 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. 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ciAny update of the data is synchronized back to AppStorage, which then synchronizes the update to all data and custom components bound to the attribute. 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ciIf the given attribute does not exist in AppStorage, **undefined** is returned. 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci> **NOTE** 362e41f4b71Sopenharmony_ci> 363e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [link10+](#link10) instead. 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci**Parameters** 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 370e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 371e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci**Return value** 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci| Type | Description | 376e41f4b71Sopenharmony_ci| -------------------------------- | ------------------------------------------------------------ | 377e41f4b71Sopenharmony_ci| any | Returns two-way bound data if specified attribute exists in AppStorage; returns **undefined** otherwise.| 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci**Example** 380e41f4b71Sopenharmony_ci```ts 381e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropA', 47); 382e41f4b71Sopenharmony_cilet linkToPropA1: SubscribedAbstractProperty<number> = AppStorage.Link('PropA'); 383e41f4b71Sopenharmony_cilet linkToPropA2: SubscribedAbstractProperty<number> = AppStorage.Link('PropA'); // linkToPropA2.get() == 47 384e41f4b71Sopenharmony_cilinkToPropA1.set(48); // Two-way synchronization: linkToPropA1.get() == linkToPropA2.get() == 48 385e41f4b71Sopenharmony_ci``` 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci### SetAndLink<sup>(deprecated)</sup> 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_cistatic SetAndLink<T>(propName: string, defaultValue: T): SubscribedAbstractProperty<T> 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ciWorks 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 **defaultValue** in AppStorage, and two-way bound data is returned. The value of **defaultValue** must be of the T type and cannot be **undefined** or **null**. 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci> **NOTE** 394e41f4b71Sopenharmony_ci> 395e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [setAndLink10+](#setandlink10) instead. 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci**Parameters** 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 402e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ------------------------------------------------------------ | 403e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage. | 404e41f4b71Sopenharmony_ci| defaultValue | T | Yes | Default value used to initialize the attribute with the specified attribute name in AppStorage. The value cannot be **undefined** or **null**.| 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci**Return value** 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci| Type | Description | 409e41f4b71Sopenharmony_ci| ----------------------------------- | ---------------------------------------- | 410e41f4b71Sopenharmony_ci| SubscribedAbstractProperty<T> | Instance of **SubscribedAbstractProperty<T>** and two-way bound data of the given attribute in AppStorage.| 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci**Example** 413e41f4b71Sopenharmony_ci```ts 414e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropA', 47); 415e41f4b71Sopenharmony_cilet link1: SubscribedAbstractProperty<number> = AppStorage.SetAndLink('PropB', 49); // Create PropB 49 416e41f4b71Sopenharmony_cilet link2: SubscribedAbstractProperty<number> = AppStorage.SetAndLink('PropA', 50); // PropA exists, remains 47 417e41f4b71Sopenharmony_ci``` 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci### Prop<sup>(deprecated)</sup> 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_cistatic Prop(propName: string): any 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ciEstablishes 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. 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci> **NOTE** 427e41f4b71Sopenharmony_ci> 428e41f4b71Sopenharmony_ci> Prop supports only simple types. 429e41f4b71Sopenharmony_ci> 430e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [prop10+](#prop10) instead. 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci**Parameters** 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 437e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 438e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci**Return value** 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci| Type | Description | 443e41f4b71Sopenharmony_ci| -------------------------------- | ------------------------------------------------------------ | 444e41f4b71Sopenharmony_ci| any | Returns one-way bound data if specified attribute exists in AppStorage; returns **undefined** otherwise.| 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci**Example** 447e41f4b71Sopenharmony_ci```ts 448e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropA', 47); 449e41f4b71Sopenharmony_cilet prop1: SubscribedAbstractProperty<number> = AppStorage.Prop('PropA'); 450e41f4b71Sopenharmony_cilet prop2: SubscribedAbstractProperty<number> = AppStorage.Prop('PropA'); 451e41f4b71Sopenharmony_ciprop1.set(1); // one-way sync: prop1.get()=1; but prop2.get() == 47 452e41f4b71Sopenharmony_ci``` 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ci### SetAndProp<sup>(deprecated)</sup> 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_cistatic SetAndProp<S>(propName: string, defaultValue: S): SubscribedAbstractProperty<S> 457e41f4b71Sopenharmony_ci 458e41f4b71Sopenharmony_ciWorks 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. The value of **defaultValue** must be of the S type and cannot be **undefined** or **null**. 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ci> **NOTE** 461e41f4b71Sopenharmony_ci> 462e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [setAndProp10+](#setandprop10) instead. 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci**Parameters** 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 469e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ------------------------------------------------------------ | 470e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage. | 471e41f4b71Sopenharmony_ci| defaultValue | S | Yes | Default value used to initialize the attribute with the specified attribute name in AppStorage. The value cannot be **undefined** or **null**.| 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**Return value** 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci| Type | Description | 476e41f4b71Sopenharmony_ci| ----------------------------------- | --------------------------------------- | 477e41f4b71Sopenharmony_ci| SubscribedAbstractProperty<S> | Instance of **SubscribedAbstractProperty<S>**.| 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci**Example** 480e41f4b71Sopenharmony_ci```ts 481e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropA', 47); 482e41f4b71Sopenharmony_cilet prop: SubscribedAbstractProperty<number> = AppStorage.SetAndProp('PropB', 49); // PropA -> 47, PropB -> 49 483e41f4b71Sopenharmony_ci``` 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci### Has<sup>(deprecated)</sup> 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_cistatic Has(propName: string): boolean 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ciChecks whether the attribute with the specified attribute name exists in AppStorage. 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci> **NOTE** 492e41f4b71Sopenharmony_ci> 493e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [has10+](#has10) instead. 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci**Parameters** 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 500e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 501e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci**Return value** 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci| Type | Description | 506e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | 507e41f4b71Sopenharmony_ci| boolean | Returns **true** if the attribute with the specified attribute name exists in AppStorage; returns **false** otherwise.| 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci**Example** 510e41f4b71Sopenharmony_ci```ts 511e41f4b71Sopenharmony_ciAppStorage.Has('simpleProp'); 512e41f4b71Sopenharmony_ci``` 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ci### Get<sup>(deprecated)</sup> 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_cistatic Get<T>(propName: string): T | undefined 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ciObtains the attribute with the specified attribute name in AppStorage. If the attribute does not exist, **undefined** is returned. 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci> **NOTE** 521e41f4b71Sopenharmony_ci> 522e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [get10+](#get10) instead. 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ci**Parameters** 527e41f4b71Sopenharmony_ci 528e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 529e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 530e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci**Return value** 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci| Type | Description | 535e41f4b71Sopenharmony_ci| ------------------------ | ------------------------------------------------------------ | 536e41f4b71Sopenharmony_ci| T \| undefined | Returns the attribute with the specified attribute name in AppStorage; returns **undefined** if the attribute does not exist.| 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_ci**Example** 539e41f4b71Sopenharmony_ci```ts 540e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropA', 47); 541e41f4b71Sopenharmony_cilet value: number = AppStorage.Get('PropA') as number; // 47 542e41f4b71Sopenharmony_ci``` 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ci### Set<sup>(deprecated)</sup> 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_cistatic Set<T>(propName: string, newValue: T): boolean 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ciSets the value for the attribute with the specified attribute name in AppStorage. 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci> **NOTE** 551e41f4b71Sopenharmony_ci> 552e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [set10+](#set10) instead. 553e41f4b71Sopenharmony_ci 554e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 555e41f4b71Sopenharmony_ci 556e41f4b71Sopenharmony_ci**Parameters** 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 559e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------------- | 560e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage. | 561e41f4b71Sopenharmony_ci| newValue | T | Yes | Attribute value, which cannot be **undefined** or **null**.| 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci**Return value** 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci| Type | Description | 566e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 567e41f4b71Sopenharmony_ci| 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**. | 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_ci**Example** 570e41f4b71Sopenharmony_ci```ts 571e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropA', 48); 572e41f4b71Sopenharmony_cilet res: boolean = AppStorage.Set('PropA', 47) // true 573e41f4b71Sopenharmony_cilet res1: boolean = AppStorage.Set('PropB', 47) // false 574e41f4b71Sopenharmony_ci``` 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci### SetOrCreate<sup>(deprecated)</sup> 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_cistatic SetOrCreate<T>(propName: string, newValue: T): void 579e41f4b71Sopenharmony_ci 580e41f4b71Sopenharmony_ciSets 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. 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_ciThe value of **newValue** cannot be **undefined** or **null**. 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_ci> **NOTE** 585e41f4b71Sopenharmony_ci> 586e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [setOrCreate10+](#setorcreate10) instead. 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 589e41f4b71Sopenharmony_ci 590e41f4b71Sopenharmony_ci**Parameters** 591e41f4b71Sopenharmony_ci 592e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 593e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------------- | 594e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage. | 595e41f4b71Sopenharmony_ci| newValue | T | Yes | Attribute value, which cannot be **undefined** or **null**.| 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_ci**Example** 598e41f4b71Sopenharmony_ci```ts 599e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('simpleProp', 121); 600e41f4b71Sopenharmony_ci``` 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ci### Delete<sup>(deprecated)</sup> 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_cistatic Delete(propName: string): boolean 605e41f4b71Sopenharmony_ci 606e41f4b71Sopenharmony_ciDeletes 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. 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ciThe 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. 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci> **NOTE** 611e41f4b71Sopenharmony_ci> 612e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [delete10+](#delete10) instead. 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci**Parameters** 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 619e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 620e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ci**Return value** 623e41f4b71Sopenharmony_ci 624e41f4b71Sopenharmony_ci| Type | Description | 625e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | 626e41f4b71Sopenharmony_ci| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ci**Example** 629e41f4b71Sopenharmony_ci```ts 630e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropA', 47); 631e41f4b71Sopenharmony_ciAppStorage.Link('PropA'); 632e41f4b71Sopenharmony_cilet res: boolean = AppStorage.Delete('PropA'); // false, PropA still has a subscriber 633e41f4b71Sopenharmony_ci 634e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropB', 48); 635e41f4b71Sopenharmony_cilet res1: boolean = AppStorage.Delete('PropB'); // true, PropB is deleted from AppStorage successfully 636e41f4b71Sopenharmony_ci``` 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci### Keys<sup>(deprecated)</sup> 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_cistatic Keys(): IterableIterator<string> 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ciObtains all attribute names in AppStorage. 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ci> **NOTE** 645e41f4b71Sopenharmony_ci> 646e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [keys10+](#keys10) instead. 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci**Return value** 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci| Type | Description | 653e41f4b71Sopenharmony_ci| ------------------------------ | ------------------ | 654e41f4b71Sopenharmony_ci| IterableIterator<string> | All attribute names in AppStorage.| 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci**Example** 657e41f4b71Sopenharmony_ci```ts 658e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropB', 48); 659e41f4b71Sopenharmony_cilet keys: IterableIterator<string> = AppStorage.Keys(); 660e41f4b71Sopenharmony_ci``` 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ci### staticClear<sup>(deprecated)</sup> 664e41f4b71Sopenharmony_ci 665e41f4b71Sopenharmony_cistatic staticClear(): boolean 666e41f4b71Sopenharmony_ci 667e41f4b71Sopenharmony_ciDeletes all attributes. 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_ci> **NOTE** 670e41f4b71Sopenharmony_ci> 671e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [clear10+](#clear10) instead. 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 674e41f4b71Sopenharmony_ci 675e41f4b71Sopenharmony_ci**Return value** 676e41f4b71Sopenharmony_ci 677e41f4b71Sopenharmony_ci| Type | Description | 678e41f4b71Sopenharmony_ci| ------- | --------------------------------- | 679e41f4b71Sopenharmony_ci| boolean | Returns **true** if all attributes are deleted; returns **false** if any of the attributes is being referenced by a state variable.| 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_ci**Example** 682e41f4b71Sopenharmony_ci```ts 683e41f4b71Sopenharmony_cilet simple = AppStorage.staticClear(); 684e41f4b71Sopenharmony_ci``` 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_ci### Clear<sup>(deprecated)</sup> 688e41f4b71Sopenharmony_ci 689e41f4b71Sopenharmony_cistatic Clear(): boolean 690e41f4b71Sopenharmony_ci 691e41f4b71Sopenharmony_ciDeletes all attributes from AppStorage under the prerequisite that none of the attributes has a subscriber. If any of the attributes has a subscriber, this API does not take effect and **false** is returned. If the deletion is successful, **true** is returned. 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ciFor details about the subscriber, see [delete](#delete10). 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci> **NOTE** 696e41f4b71Sopenharmony_ci> 697e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [clear10+](#clear10) instead. 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci**Return value** 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_ci| Type | Description | 704e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 705e41f4b71Sopenharmony_ci| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ci**Example** 708e41f4b71Sopenharmony_ci```typescript 709e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropA', 47); 710e41f4b71Sopenharmony_cilet res: boolean = AppStorage.Clear(); // true, there are no subscribers 711e41f4b71Sopenharmony_ci``` 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci 714e41f4b71Sopenharmony_ci### IsMutable<sup>(deprecated)</sup> 715e41f4b71Sopenharmony_ci 716e41f4b71Sopenharmony_cistatic IsMutable(propName: string): boolean 717e41f4b71Sopenharmony_ci 718e41f4b71Sopenharmony_ciChecks whether the given attribute in AppStorage name is mutable. 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci> **NOTE** 721e41f4b71Sopenharmony_ci> 722e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. 723e41f4b71Sopenharmony_ci 724e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 725e41f4b71Sopenharmony_ci 726e41f4b71Sopenharmony_ci**Parameters** 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 729e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- | 730e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in AppStorage.| 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_ci**Return value** 733e41f4b71Sopenharmony_ci 734e41f4b71Sopenharmony_ci| Type | Description | 735e41f4b71Sopenharmony_ci| ------- | -------------------------------- | 736e41f4b71Sopenharmony_ci| boolean | Whether the given attribute in AppStorage name is mutable.| 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_ci**Example** 739e41f4b71Sopenharmony_ci```ts 740e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropA', 47); 741e41f4b71Sopenharmony_cilet res: boolean = AppStorage.IsMutable('simpleProp'); 742e41f4b71Sopenharmony_ci``` 743e41f4b71Sopenharmony_ci 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci### Size<sup>(deprecated)</sup> 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_cistatic Size(): number 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ciObtains the number of attributes in AppStorage. 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci> **NOTE** 752e41f4b71Sopenharmony_ci> 753e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [size10+](#size10) instead. 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci**Return value** 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci| Type | Description | 760e41f4b71Sopenharmony_ci| ------ | ------------------- | 761e41f4b71Sopenharmony_ci| number | Number of attributes in AppStorage.| 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci**Example** 764e41f4b71Sopenharmony_ci```ts 765e41f4b71Sopenharmony_ciAppStorage.SetOrCreate('PropB', 48); 766e41f4b71Sopenharmony_cilet res: number = AppStorage.Size(); // 1 767e41f4b71Sopenharmony_ci``` 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_ci## LocalStorage<sup>9+</sup> 771e41f4b71Sopenharmony_ci 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_ciFor details about how to use LocalStorage on the UI, see [LocalStorage: UI State Storage](../../../quick-start/arkts-localstorage.md). 774e41f4b71Sopenharmony_ci 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ci### constructor<sup>9+</sup> 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ciconstructor(initializingProperties?: Object) 779e41f4b71Sopenharmony_ci 780e41f4b71Sopenharmony_ciCreates a **LocalStorage** instance and initializes it using the attributes and values returned by **Object.keys(initializingProperties)**. 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ci> **NOTE** 783e41f4b71Sopenharmony_ci> 784e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 785e41f4b71Sopenharmony_ci 786e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 787e41f4b71Sopenharmony_ci 788e41f4b71Sopenharmony_ci**Parameters** 789e41f4b71Sopenharmony_ci 790e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 791e41f4b71Sopenharmony_ci| ---------------------- | ------ | ---- | ---------------------------------------- | 792e41f4b71Sopenharmony_ci| initializingProperties | Object | No | Attributes and values used to initialize the **LocalStorage** instance. The value cannot be **undefined**.| 793e41f4b71Sopenharmony_ci 794e41f4b71Sopenharmony_ci**Example** 795e41f4b71Sopenharmony_ci```ts 796e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 797e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 798e41f4b71Sopenharmony_ci``` 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_ci### getShared<sup>10+</sup> 802e41f4b71Sopenharmony_ci 803e41f4b71Sopenharmony_cistatic getShared(): LocalStorage 804e41f4b71Sopenharmony_ci 805e41f4b71Sopenharmony_ciObtains the **LocalStorage** instance shared by the current stage. 806e41f4b71Sopenharmony_ci 807e41f4b71Sopenharmony_ci> **NOTE** 808e41f4b71Sopenharmony_ci> 809e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 810e41f4b71Sopenharmony_ci 811e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 812e41f4b71Sopenharmony_ci 813e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 814e41f4b71Sopenharmony_ci 815e41f4b71Sopenharmony_ci**Return value** 816e41f4b71Sopenharmony_ci 817e41f4b71Sopenharmony_ci| Type | Description | 818e41f4b71Sopenharmony_ci| ------------------------------ | ----------------- | 819e41f4b71Sopenharmony_ci| [LocalStorage](#localstorage9) | **LocalStorage** instance.| 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ci**Example** 822e41f4b71Sopenharmony_ciFor details about how to use **getShared**, see [Sharing a LocalStorage Instance from UIAbility to One or More Pages](../../../quick-start/arkts-localstorage.md#example-of-sharing-a-localstorage-instance-from-uiability-to-one-or-more-pages). 823e41f4b71Sopenharmony_ci 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_ci### has<sup>9+</sup> 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_cihas(propName: string): boolean 828e41f4b71Sopenharmony_ci 829e41f4b71Sopenharmony_ciChecks whether the attribute with the specified attribute name exists in LocalStorage. 830e41f4b71Sopenharmony_ci 831e41f4b71Sopenharmony_ci> **NOTE** 832e41f4b71Sopenharmony_ci> 833e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 836e41f4b71Sopenharmony_ci 837e41f4b71Sopenharmony_ci**Parameters** 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 840e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------ | 841e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in LocalStorage.| 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ci**Return value** 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_ci| Type | Description | 846e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 847e41f4b71Sopenharmony_ci| boolean | Returns **true** if the attribute with the specified attribute name exists in LocalStorage; returns **false** otherwise.| 848e41f4b71Sopenharmony_ci 849e41f4b71Sopenharmony_ci**Example** 850e41f4b71Sopenharmony_ci```ts 851e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 852e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 853e41f4b71Sopenharmony_cistorage.has('PropA'); // true 854e41f4b71Sopenharmony_ci``` 855e41f4b71Sopenharmony_ci 856e41f4b71Sopenharmony_ci 857e41f4b71Sopenharmony_ci### get<sup>9+</sup> 858e41f4b71Sopenharmony_ci 859e41f4b71Sopenharmony_ciget<T>(propName: string): T | undefined 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ciObtains the attribute with the specified attribute name in LocalStorage. 862e41f4b71Sopenharmony_ci 863e41f4b71Sopenharmony_ci> **NOTE** 864e41f4b71Sopenharmony_ci> 865e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 866e41f4b71Sopenharmony_ci 867e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 868e41f4b71Sopenharmony_ci 869e41f4b71Sopenharmony_ci**Parameters** 870e41f4b71Sopenharmony_ci 871e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 872e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------ | 873e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in LocalStorage.| 874e41f4b71Sopenharmony_ci 875e41f4b71Sopenharmony_ci**Return value** 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ci| Type | Description | 878e41f4b71Sopenharmony_ci| ------------------------ | ------------------------------------------------------------ | 879e41f4b71Sopenharmony_ci| T \| undefined | Returns the attribute with the specified attribute name in LocalStorage; returns **undefined** if the attribute does not exist.| 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_ci**Example** 882e41f4b71Sopenharmony_ci```ts 883e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 884e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 885e41f4b71Sopenharmony_cilet value: number = storage.get('PropA') as number; // 47 886e41f4b71Sopenharmony_ci``` 887e41f4b71Sopenharmony_ci 888e41f4b71Sopenharmony_ci 889e41f4b71Sopenharmony_ci### set<sup>9+</sup> 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ciset<T>(propName: string, newValue: T): boolean 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ciSets a value for the attribute with the specified attribute name in LocalStorage. If the value of **newValue** is the same as the value of the attribute with the specified attribute name, that is, no value needs to be assigned, the state variable will not instruct the UI to update the value of attribute. 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci> **NOTE** 896e41f4b71Sopenharmony_ci> 897e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 898e41f4b71Sopenharmony_ci 899e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 900e41f4b71Sopenharmony_ci 901e41f4b71Sopenharmony_ci**Parameters** 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 904e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------- | 905e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in LocalStorage. | 906e41f4b71Sopenharmony_ci| newValue | T | Yes | Attribute value, which cannot be **undefined** or **null**.| 907e41f4b71Sopenharmony_ci 908e41f4b71Sopenharmony_ci**Return value** 909e41f4b71Sopenharmony_ci 910e41f4b71Sopenharmony_ci| Type | Description | 911e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 912e41f4b71Sopenharmony_ci| 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**. | 913e41f4b71Sopenharmony_ci 914e41f4b71Sopenharmony_ci**Example** 915e41f4b71Sopenharmony_ci 916e41f4b71Sopenharmony_ci```ts 917e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 918e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 919e41f4b71Sopenharmony_cilet res: boolean = storage.set('PropA', 47); // true 920e41f4b71Sopenharmony_cilet res1: boolean = storage.set('PropB', 47); // false 921e41f4b71Sopenharmony_ci``` 922e41f4b71Sopenharmony_ci 923e41f4b71Sopenharmony_ci 924e41f4b71Sopenharmony_ci### setOrCreate<sup>9+</sup> 925e41f4b71Sopenharmony_ci 926e41f4b71Sopenharmony_cisetOrCreate<T>(propName: string, newValue: T): boolean 927e41f4b71Sopenharmony_ci 928e41f4b71Sopenharmony_ciSets 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 the set value. 929e41f4b71Sopenharmony_ciIf the new value is the same as the existing value of the attribute with the specified attribute name, the state variable will not instruct the UI to update the value of the attribute. This **setOrCreate** method creates only one LocalStorage key-value pair. To create multiple key-value pairs, call this method multiple times. 930e41f4b71Sopenharmony_ci 931e41f4b71Sopenharmony_ci> **NOTE** 932e41f4b71Sopenharmony_ci> 933e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 934e41f4b71Sopenharmony_ci 935e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 936e41f4b71Sopenharmony_ci 937e41f4b71Sopenharmony_ci**Parameters** 938e41f4b71Sopenharmony_ci 939e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 940e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------- | 941e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in LocalStorage. | 942e41f4b71Sopenharmony_ci| newValue | T | Yes | Attribute value, which cannot be **undefined** or **null**.| 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci**Return value** 945e41f4b71Sopenharmony_ci 946e41f4b71Sopenharmony_ci| Type | Description | 947e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 948e41f4b71Sopenharmony_ci| 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.| 949e41f4b71Sopenharmony_ci 950e41f4b71Sopenharmony_ci**Example** 951e41f4b71Sopenharmony_ci 952e41f4b71Sopenharmony_ci```ts 953e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 954e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 955e41f4b71Sopenharmony_cilet res: boolean = storage.setOrCreate('PropA', 121); // true 956e41f4b71Sopenharmony_cilet res1: boolean = storage.setOrCreate('PropB', 111); // true 957e41f4b71Sopenharmony_cilet res2: boolean = storage.setOrCreate('PropB', null); // false 958e41f4b71Sopenharmony_ci``` 959e41f4b71Sopenharmony_ci 960e41f4b71Sopenharmony_ci 961e41f4b71Sopenharmony_ci### link<sup>9+</sup> 962e41f4b71Sopenharmony_ci 963e41f4b71Sopenharmony_cilink<T>(propName: string): SubscribedAbstractProperty<T> 964e41f4b71Sopenharmony_ci 965e41f4b71Sopenharmony_ciEstablishes 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. 966e41f4b71Sopenharmony_ci 967e41f4b71Sopenharmony_ciAny update of the data is synchronized back to LocalStorage, which then synchronizes the update to all data and custom components bound to the attribute. 968e41f4b71Sopenharmony_ci 969e41f4b71Sopenharmony_ciIf the given attribute does not exist in LocalStorage, **undefined** is returned. 970e41f4b71Sopenharmony_ci 971e41f4b71Sopenharmony_ci> **NOTE** 972e41f4b71Sopenharmony_ci> 973e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 974e41f4b71Sopenharmony_ci 975e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 976e41f4b71Sopenharmony_ci 977e41f4b71Sopenharmony_ci**Parameters** 978e41f4b71Sopenharmony_ci 979e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 980e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------ | 981e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in LocalStorage.| 982e41f4b71Sopenharmony_ci 983e41f4b71Sopenharmony_ci**Return value** 984e41f4b71Sopenharmony_ci 985e41f4b71Sopenharmony_ci| Type | Description | 986e41f4b71Sopenharmony_ci| ----------------------------------- | ------------------------------------------------------------ | 987e41f4b71Sopenharmony_ci| SubscribedAbstractProperty<T> | Returns the **SubscribedAbstractProperty<T>** instance if the given attribute exists in LocalStorage; returns undefined otherwise.| 988e41f4b71Sopenharmony_ci 989e41f4b71Sopenharmony_ci**Example** 990e41f4b71Sopenharmony_ci```ts 991e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 992e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 993e41f4b71Sopenharmony_cilet linkToPropA1: SubscribedAbstractProperty<number> = storage.link('PropA'); 994e41f4b71Sopenharmony_cilet linkToPropA2: SubscribedAbstractProperty<number> = storage.link('PropA'); // linkToPropA2.get() == 47 995e41f4b71Sopenharmony_cilinkToPropA1.set(48); // Two-way synchronization: linkToPropA1.get() == linkToPropA2.get() == 48 996e41f4b71Sopenharmony_ci``` 997e41f4b71Sopenharmony_ci 998e41f4b71Sopenharmony_ci 999e41f4b71Sopenharmony_ci### setAndLink<sup>9+</sup> 1000e41f4b71Sopenharmony_ci 1001e41f4b71Sopenharmony_cisetAndLink<T>(propName: string, defaultValue: T): SubscribedAbstractProperty<T> 1002e41f4b71Sopenharmony_ci 1003e41f4b71Sopenharmony_ciWorks in a way similar to the **link** API. If the given attribute exists in LocalStorage, 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 **defaultValue** in LocalStorage, and two-way bound data is returned. The value of **defaultValue** must be of the T type and cannot be **undefined** or **null**. 1004e41f4b71Sopenharmony_ci 1005e41f4b71Sopenharmony_ci> **NOTE** 1006e41f4b71Sopenharmony_ci> 1007e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 1008e41f4b71Sopenharmony_ci 1009e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1010e41f4b71Sopenharmony_ci 1011e41f4b71Sopenharmony_ci**Parameters** 1012e41f4b71Sopenharmony_ci 1013e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1014e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ------------------------------------------------------------ | 1015e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in LocalStorage. | 1016e41f4b71Sopenharmony_ci| defaultValue | T | Yes | Default value used to initialize the attribute with the specified attribute name in LocalStorage. The value cannot be **undefined** or **null**.| 1017e41f4b71Sopenharmony_ci 1018e41f4b71Sopenharmony_ci**Return value** 1019e41f4b71Sopenharmony_ci 1020e41f4b71Sopenharmony_ci| Type | Description | 1021e41f4b71Sopenharmony_ci| ----------------------------------- | ------------------------------------------------------------ | 1022e41f4b71Sopenharmony_ci| SubscribedAbstractProperty<T> | Instance of **SubscribedAbstractProperty<T>** and two-way bound data of the given attribute in LocalStorage.| 1023e41f4b71Sopenharmony_ci 1024e41f4b71Sopenharmony_ci**Example** 1025e41f4b71Sopenharmony_ci```ts 1026e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 1027e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 1028e41f4b71Sopenharmony_cilet link1: SubscribedAbstractProperty<number> = storage.setAndLink('PropB', 49); // Create PropB 49 1029e41f4b71Sopenharmony_cilet link2: SubscribedAbstractProperty<number> = storage.setAndLink('PropA', 50); // PropA exists, remains 47 1030e41f4b71Sopenharmony_ci``` 1031e41f4b71Sopenharmony_ci 1032e41f4b71Sopenharmony_ci 1033e41f4b71Sopenharmony_ci### prop<sup>9+</sup> 1034e41f4b71Sopenharmony_ci 1035e41f4b71Sopenharmony_ciprop<S>(propName: string): SubscribedAbstractProperty<S> 1036e41f4b71Sopenharmony_ci 1037e41f4b71Sopenharmony_ciEstablishes 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. 1038e41f4b71Sopenharmony_ci 1039e41f4b71Sopenharmony_ci> **NOTE** 1040e41f4b71Sopenharmony_ci> 1041e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 1042e41f4b71Sopenharmony_ci 1043e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1044e41f4b71Sopenharmony_ci 1045e41f4b71Sopenharmony_ci**Parameters** 1046e41f4b71Sopenharmony_ci 1047e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1048e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------ | 1049e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in LocalStorage.| 1050e41f4b71Sopenharmony_ci 1051e41f4b71Sopenharmony_ci**Return value** 1052e41f4b71Sopenharmony_ci 1053e41f4b71Sopenharmony_ci| Type | Description | 1054e41f4b71Sopenharmony_ci| ----------------------------------- | ------------------------------------------------------------ | 1055e41f4b71Sopenharmony_ci| SubscribedAbstractProperty<S> | Returns the **SubscribedAbstractProperty<S>** instance if the given attribute exists in LocalStorage; returns **undefined** otherwise.| 1056e41f4b71Sopenharmony_ci 1057e41f4b71Sopenharmony_ci**Example** 1058e41f4b71Sopenharmony_ci```ts 1059e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 1060e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 1061e41f4b71Sopenharmony_cilet prop1: SubscribedAbstractProperty<number> = storage.prop('PropA'); 1062e41f4b71Sopenharmony_cilet prop2: SubscribedAbstractProperty<number> = storage.prop('PropA'); 1063e41f4b71Sopenharmony_ciprop1.set(1); // one-way sync: prop1.get()=1; but prop2.get() == 47 1064e41f4b71Sopenharmony_ci``` 1065e41f4b71Sopenharmony_ci 1066e41f4b71Sopenharmony_ci 1067e41f4b71Sopenharmony_ci### setAndProp<sup>9+</sup> 1068e41f4b71Sopenharmony_ci 1069e41f4b71Sopenharmony_cisetAndProp<S>(propName: string, defaultValue: S): SubscribedAbstractProperty<S> 1070e41f4b71Sopenharmony_ci 1071e41f4b71Sopenharmony_ciWorks in a way similar to the **prop** API. If the given attribute exists in LocalStorage, 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. The value of **defaultValue** must be of the S type and cannot be **undefined** or **null**. 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ci> **NOTE** 1074e41f4b71Sopenharmony_ci> 1075e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci**Parameters** 1080e41f4b71Sopenharmony_ci 1081e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1082e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ------------------------------------------------------------ | 1083e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in LocalStorage. | 1084e41f4b71Sopenharmony_ci| defaultValue | S | Yes | Default value used to initialize the attribute with the specified attribute name in LocalStorage. The value cannot be **undefined** or **null**.| 1085e41f4b71Sopenharmony_ci 1086e41f4b71Sopenharmony_ci**Return value** 1087e41f4b71Sopenharmony_ci 1088e41f4b71Sopenharmony_ci| Type | Description | 1089e41f4b71Sopenharmony_ci| ----------------------------------- | ------------------------------------------------------------ | 1090e41f4b71Sopenharmony_ci| SubscribedAbstractProperty<S> | Instance of **SubscribedAbstractProperty<S>** and one-way bound data of the given attribute in LocalStorage.| 1091e41f4b71Sopenharmony_ci 1092e41f4b71Sopenharmony_ci**Example** 1093e41f4b71Sopenharmony_ci 1094e41f4b71Sopenharmony_ci```ts 1095e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 1096e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 1097e41f4b71Sopenharmony_cilet prop: SubscribedAbstractProperty<number> = storage.setAndProp('PropB', 49); // PropA -> 47, PropB -> 49 1098e41f4b71Sopenharmony_ci``` 1099e41f4b71Sopenharmony_ci 1100e41f4b71Sopenharmony_ci 1101e41f4b71Sopenharmony_ci### delete<sup>9+</sup> 1102e41f4b71Sopenharmony_ci 1103e41f4b71Sopenharmony_cidelete(propName: string): boolean 1104e41f4b71Sopenharmony_ci 1105e41f4b71Sopenharmony_ciDeletes the attribute with the specified attribute name from LocalStorage 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. 1106e41f4b71Sopenharmony_ci 1107e41f4b71Sopenharmony_ciThe subscribers of the attribute are attributes with the same name bound to APIs such as **link** and **prop**, and **\@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 LocalStorage. 1108e41f4b71Sopenharmony_ci 1109e41f4b71Sopenharmony_ci> **NOTE** 1110e41f4b71Sopenharmony_ci> 1111e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci**Parameters** 1116e41f4b71Sopenharmony_ci 1117e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1118e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------ | 1119e41f4b71Sopenharmony_ci| propName | string | Yes | Attribute name in LocalStorage.| 1120e41f4b71Sopenharmony_ci 1121e41f4b71Sopenharmony_ci**Return value** 1122e41f4b71Sopenharmony_ci 1123e41f4b71Sopenharmony_ci| Type | Description | 1124e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 1125e41f4b71Sopenharmony_ci| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1126e41f4b71Sopenharmony_ci 1127e41f4b71Sopenharmony_ci**Example** 1128e41f4b71Sopenharmony_ci```ts 1129e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 1130e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 1131e41f4b71Sopenharmony_cistorage.link<number>('PropA'); 1132e41f4b71Sopenharmony_cilet res: boolean = storage.delete('PropA'); // false, PropA still has a subscriber 1133e41f4b71Sopenharmony_cilet res1: boolean = storage.delete('PropB'); // false, PropB is not in storage 1134e41f4b71Sopenharmony_cistorage.setOrCreate('PropB', 48); 1135e41f4b71Sopenharmony_cilet res2: boolean = storage.delete('PropB'); // true, PropB is deleted from storage successfully 1136e41f4b71Sopenharmony_ci``` 1137e41f4b71Sopenharmony_ci 1138e41f4b71Sopenharmony_ci 1139e41f4b71Sopenharmony_ci### keys<sup>9+</sup> 1140e41f4b71Sopenharmony_ci 1141e41f4b71Sopenharmony_cikeys(): IterableIterator<string> 1142e41f4b71Sopenharmony_ci 1143e41f4b71Sopenharmony_ciObtains all attribute names in LocalStorage. 1144e41f4b71Sopenharmony_ci 1145e41f4b71Sopenharmony_ci> **NOTE** 1146e41f4b71Sopenharmony_ci> 1147e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 1148e41f4b71Sopenharmony_ci 1149e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1150e41f4b71Sopenharmony_ci 1151e41f4b71Sopenharmony_ci**Return value** 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ci| Type | Description | 1154e41f4b71Sopenharmony_ci| ------------------------------ | -------------------- | 1155e41f4b71Sopenharmony_ci| IterableIterator<string> | All attribute names in LocalStorage.| 1156e41f4b71Sopenharmony_ci 1157e41f4b71Sopenharmony_ci**Example** 1158e41f4b71Sopenharmony_ci```ts 1159e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 1160e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 1161e41f4b71Sopenharmony_cilet keys: IterableIterator<string> = storage.keys(); 1162e41f4b71Sopenharmony_ci``` 1163e41f4b71Sopenharmony_ci 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ci### size<sup>9+</sup> 1166e41f4b71Sopenharmony_ci 1167e41f4b71Sopenharmony_cisize(): number 1168e41f4b71Sopenharmony_ci 1169e41f4b71Sopenharmony_ciObtains the number of attributes in LocalStorage. 1170e41f4b71Sopenharmony_ci 1171e41f4b71Sopenharmony_ci> **NOTE** 1172e41f4b71Sopenharmony_ci> 1173e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 1174e41f4b71Sopenharmony_ci 1175e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1176e41f4b71Sopenharmony_ci 1177e41f4b71Sopenharmony_ci**Return value** 1178e41f4b71Sopenharmony_ci 1179e41f4b71Sopenharmony_ci| Type | Description | 1180e41f4b71Sopenharmony_ci| ------ | ---------------------------- | 1181e41f4b71Sopenharmony_ci| number | Number of attributes in LocalStorage.| 1182e41f4b71Sopenharmony_ci 1183e41f4b71Sopenharmony_ci**Example** 1184e41f4b71Sopenharmony_ci```ts 1185e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 1186e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 1187e41f4b71Sopenharmony_cilet res: number = storage.size(); // 1 1188e41f4b71Sopenharmony_ci``` 1189e41f4b71Sopenharmony_ci 1190e41f4b71Sopenharmony_ci 1191e41f4b71Sopenharmony_ci### clear<sup>9+</sup> 1192e41f4b71Sopenharmony_ci 1193e41f4b71Sopenharmony_ciclear(): boolean 1194e41f4b71Sopenharmony_ci 1195e41f4b71Sopenharmony_ciDeletes all attributes from LocalStorage under the prerequisite that none of the attributes has a subscriber. If any of the attributes has a subscriber, this API does not take effect and **false** is returned. If the deletion is successful, **true** is returned. 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ciFor details about the subscriber, see [delete](#delete9). 1198e41f4b71Sopenharmony_ci 1199e41f4b71Sopenharmony_ci> **NOTE** 1200e41f4b71Sopenharmony_ci> 1201e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 1202e41f4b71Sopenharmony_ci 1203e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1204e41f4b71Sopenharmony_ci 1205e41f4b71Sopenharmony_ci**Return value** 1206e41f4b71Sopenharmony_ci 1207e41f4b71Sopenharmony_ci 1208e41f4b71Sopenharmony_ci| Type | Description | 1209e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 1210e41f4b71Sopenharmony_ci| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1211e41f4b71Sopenharmony_ci 1212e41f4b71Sopenharmony_ci 1213e41f4b71Sopenharmony_ci**Example** 1214e41f4b71Sopenharmony_ci```ts 1215e41f4b71Sopenharmony_cilet para: Record<string, number> = { 'PropA': 47 }; 1216e41f4b71Sopenharmony_cilet storage: LocalStorage = new LocalStorage(para); 1217e41f4b71Sopenharmony_cilet res: boolean = storage.clear(); // true, there are no subscribers 1218e41f4b71Sopenharmony_ci``` 1219e41f4b71Sopenharmony_ci 1220e41f4b71Sopenharmony_ci 1221e41f4b71Sopenharmony_ci### GetShared<sup>(deprecated)</sup> 1222e41f4b71Sopenharmony_ci 1223e41f4b71Sopenharmony_cistatic GetShared(): LocalStorage 1224e41f4b71Sopenharmony_ci 1225e41f4b71Sopenharmony_ciObtains the **LocalStorage** instance shared by the current stage. 1226e41f4b71Sopenharmony_ci 1227e41f4b71Sopenharmony_ci> **NOTE** 1228e41f4b71Sopenharmony_ci> 1229e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 1230e41f4b71Sopenharmony_ci> 1231e41f4b71Sopenharmony_ci> This API is deprecated since API version 10. You are advised to use [getShared10+](#getshared10) instead. 1232e41f4b71Sopenharmony_ci 1233e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 1236e41f4b71Sopenharmony_ci 1237e41f4b71Sopenharmony_ci**Return value** 1238e41f4b71Sopenharmony_ci 1239e41f4b71Sopenharmony_ci| Type | Description | 1240e41f4b71Sopenharmony_ci| ------------------------------ | ----------------- | 1241e41f4b71Sopenharmony_ci| [LocalStorage](#localstorage9) | **LocalStorage** instance.| 1242e41f4b71Sopenharmony_ci 1243e41f4b71Sopenharmony_ci**Example** 1244e41f4b71Sopenharmony_ci```ts 1245e41f4b71Sopenharmony_cilet storage: LocalStorage = LocalStorage.GetShared(); 1246e41f4b71Sopenharmony_ci``` 1247e41f4b71Sopenharmony_ci 1248e41f4b71Sopenharmony_ci 1249e41f4b71Sopenharmony_ci## SubscribedAbstractProperty 1250e41f4b71Sopenharmony_ci 1251e41f4b71Sopenharmony_ci 1252e41f4b71Sopenharmony_ci### get<sup>9+</sup> 1253e41f4b71Sopenharmony_ci 1254e41f4b71Sopenharmony_ciabstract get(): T 1255e41f4b71Sopenharmony_ci 1256e41f4b71Sopenharmony_ciObtains attribute data synchronized from AppStorage or LocalStorage. 1257e41f4b71Sopenharmony_ci 1258e41f4b71Sopenharmony_ci> **NOTE** 1259e41f4b71Sopenharmony_ci> 1260e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 1261e41f4b71Sopenharmony_ci 1262e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1263e41f4b71Sopenharmony_ci 1264e41f4b71Sopenharmony_ci**Return value** 1265e41f4b71Sopenharmony_ci 1266e41f4b71Sopenharmony_ci| Type | Description | 1267e41f4b71Sopenharmony_ci| ---- | ------------------------------- | 1268e41f4b71Sopenharmony_ci| T | Attribute data synchronized from AppStorage or LocalStorage.| 1269e41f4b71Sopenharmony_ci 1270e41f4b71Sopenharmony_ci**Example** 1271e41f4b71Sopenharmony_ci```ts 1272e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 47); 1273e41f4b71Sopenharmony_cilet prop1: SubscribedAbstractProperty<number> = AppStorage.prop('PropA'); 1274e41f4b71Sopenharmony_ciprop1.get(); // prop1.get()=47 1275e41f4b71Sopenharmony_ci``` 1276e41f4b71Sopenharmony_ci 1277e41f4b71Sopenharmony_ci 1278e41f4b71Sopenharmony_ci### set<sup>9+</sup> 1279e41f4b71Sopenharmony_ci 1280e41f4b71Sopenharmony_ciabstract set(newValue: T): void 1281e41f4b71Sopenharmony_ci 1282e41f4b71Sopenharmony_ciSets the attribute data synchronized from AppStorage or LocalStorage. The value of **newValue** must be of the T type and cannot be **undefined** or **null**. 1283e41f4b71Sopenharmony_ci 1284e41f4b71Sopenharmony_ci> **NOTE** 1285e41f4b71Sopenharmony_ci> 1286e41f4b71Sopenharmony_ci> This API can be used in ArkTS widgets since API version 9. 1287e41f4b71Sopenharmony_ci 1288e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1289e41f4b71Sopenharmony_ci 1290e41f4b71Sopenharmony_ci 1291e41f4b71Sopenharmony_ci**Parameters** 1292e41f4b71Sopenharmony_ci 1293e41f4b71Sopenharmony_ci 1294e41f4b71Sopenharmony_ci| Name | Type| Mandatory| Description | 1295e41f4b71Sopenharmony_ci| -------- | ---- | ---- | ------------------------------------- | 1296e41f4b71Sopenharmony_ci| newValue | T | Yes | Data to set. The value cannot be **undefined** or **null**.| 1297e41f4b71Sopenharmony_ci 1298e41f4b71Sopenharmony_ci 1299e41f4b71Sopenharmony_ci**Example** 1300e41f4b71Sopenharmony_ci```ts 1301e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 47); 1302e41f4b71Sopenharmony_cilet prop1: SubscribedAbstractProperty<number> = AppStorage.prop('PropA'); 1303e41f4b71Sopenharmony_ciprop1.set(1); // prop1.get()=1 1304e41f4b71Sopenharmony_ci``` 1305e41f4b71Sopenharmony_ci 1306e41f4b71Sopenharmony_ci### aboutToBeDeleted<sup>10+</sup> 1307e41f4b71Sopenharmony_ci 1308e41f4b71Sopenharmony_ciabstract aboutToBeDeleted(): void 1309e41f4b71Sopenharmony_ci 1310e41f4b71Sopenharmony_ciCancels one-way or two-way synchronization between the **SubscribedAbstractProperty** instance and AppStorage or LocalStorage, and invalidates the instance. After this API is called, the **SubscribedAbstractProperty** instance cannot be used to call the setter or getter. 1311e41f4b71Sopenharmony_ci 1312e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1313e41f4b71Sopenharmony_ci 1314e41f4b71Sopenharmony_ci**Example** 1315e41f4b71Sopenharmony_ci```ts 1316e41f4b71Sopenharmony_ciAppStorage.setOrCreate('PropA', 47); 1317e41f4b71Sopenharmony_cilet link = AppStorage.setAndLink('PropB', 49); // PropA -> 47, PropB -> 49 1318e41f4b71Sopenharmony_cilink.aboutToBeDeleted(); 1319e41f4b71Sopenharmony_ci``` 1320e41f4b71Sopenharmony_ci 1321e41f4b71Sopenharmony_ci 1322e41f4b71Sopenharmony_ci## PersistentStorage 1323e41f4b71Sopenharmony_ci 1324e41f4b71Sopenharmony_ci 1325e41f4b71Sopenharmony_ciFor details about how to use PersistentStorage on the UI, see [PersistentStorage: Application State Persistence](../../../quick-start/arkts-persiststorage.md). 1326e41f4b71Sopenharmony_ci 1327e41f4b71Sopenharmony_ci### PersistPropsOptions 1328e41f4b71Sopenharmony_ci 1329e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1330e41f4b71Sopenharmony_ci 1331e41f4b71Sopenharmony_ci**Parameters** 1332e41f4b71Sopenharmony_ci 1333e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1334e41f4b71Sopenharmony_ci| ------------ | ------------------------------------- | ---- | ------------------------------------------------------------ | 1335e41f4b71Sopenharmony_ci| key | string | Yes | Attribute name. | 1336e41f4b71Sopenharmony_ci| defaultValue | number \| string \| boolean \| Object | Yes | Default value used to initialize the created attribute when the corresponding attribute is not found in PersistentStorage and AppStorage. The value cannot be **undefined** or **null**.| 1337e41f4b71Sopenharmony_ci 1338e41f4b71Sopenharmony_ci 1339e41f4b71Sopenharmony_ci### persistProp<sup>10+</sup> 1340e41f4b71Sopenharmony_ci 1341e41f4b71Sopenharmony_cistatic persistProp<T>(key: string, defaultValue: T): void 1342e41f4b71Sopenharmony_ci 1343e41f4b71Sopenharmony_ciPersists the attribute with the specified key in AppStorage to a file. This API is usually called before access to AppStorage. 1344e41f4b71Sopenharmony_ci 1345e41f4b71Sopenharmony_ciThe sequence of determining the type and value of an attribute is as follows: 1346e41f4b71Sopenharmony_ci 1347e41f4b71Sopenharmony_ci1. 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. 1348e41f4b71Sopenharmony_ci 1349e41f4b71Sopenharmony_ci2. 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. 1350e41f4b71Sopenharmony_ci 1351e41f4b71Sopenharmony_ci3. If no matching attribute is found in AppStorage, it is created in AppStorage, initialized with the value of **defaultValue**, and persisted. 1352e41f4b71Sopenharmony_ci 1353e41f4b71Sopenharmony_ciAccording 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 nonpersistent. 1354e41f4b71Sopenharmony_ci 1355e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1356e41f4b71Sopenharmony_ci 1357e41f4b71Sopenharmony_ci**Parameters** 1358e41f4b71Sopenharmony_ci 1359e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1360e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ------------------------------------------------------------ | 1361e41f4b71Sopenharmony_ci| key | string | Yes | Attribute name. | 1362e41f4b71Sopenharmony_ci| defaultValue | T | Yes | Default value used to initialize the created attribute. The value cannot be **undefined** or **null**.| 1363e41f4b71Sopenharmony_ci 1364e41f4b71Sopenharmony_ci 1365e41f4b71Sopenharmony_ci**Example** 1366e41f4b71Sopenharmony_ci 1367e41f4b71Sopenharmony_ci 1368e41f4b71Sopenharmony_ciFor details about how to use persistProp, see [Accessing PersistentStorage Initialized Attribute from AppStorage](../../../quick-start/arkts-persiststorage.md#accessing-persistentstorage-initialized-attribute-from-appstorage). 1369e41f4b71Sopenharmony_ci 1370e41f4b71Sopenharmony_ci 1371e41f4b71Sopenharmony_ci### deleteProp<sup>10+</sup> 1372e41f4b71Sopenharmony_ci 1373e41f4b71Sopenharmony_cistatic deleteProp(key: string): void 1374e41f4b71Sopenharmony_ci 1375e41f4b71Sopenharmony_ciPerforms the reverse operation of **persistProp**. Specifically, this API deletes the attribute corresponding to the specified key from PersistentStorage. Subsequent AppStorage operations do not affect data in PersistentStorage. 1376e41f4b71Sopenharmony_ci 1377e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1378e41f4b71Sopenharmony_ci 1379e41f4b71Sopenharmony_ci**Parameters** 1380e41f4b71Sopenharmony_ci 1381e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1382e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ----------------------- | 1383e41f4b71Sopenharmony_ci| key | string | Yes | Attribute name in PersistentStorage.| 1384e41f4b71Sopenharmony_ci 1385e41f4b71Sopenharmony_ci**Example** 1386e41f4b71Sopenharmony_ci```ts 1387e41f4b71Sopenharmony_ciPersistentStorage.deleteProp('highScore'); 1388e41f4b71Sopenharmony_ci``` 1389e41f4b71Sopenharmony_ci 1390e41f4b71Sopenharmony_ci 1391e41f4b71Sopenharmony_ci### persistProps<sup>10+</sup> 1392e41f4b71Sopenharmony_ci 1393e41f4b71Sopenharmony_cistatic persistProps(props: PersistPropsOptions[]): void 1394e41f4b71Sopenharmony_ci 1395e41f4b71Sopenharmony_ciWorks 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. 1396e41f4b71Sopenharmony_ci 1397e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1398e41f4b71Sopenharmony_ci 1399e41f4b71Sopenharmony_ci**Parameters** 1400e41f4b71Sopenharmony_ci 1401e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1402e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | 1403e41f4b71Sopenharmony_ci| props | [PersistPropsOptions](#persistpropsoptions)[] | Yes| Array of persistent attributes.| 1404e41f4b71Sopenharmony_ci 1405e41f4b71Sopenharmony_ci**Example** 1406e41f4b71Sopenharmony_ci```ts 1407e41f4b71Sopenharmony_ciPersistentStorage.persistProps([{ key: 'highScore', defaultValue: '0' }, { key: 'wightScore', defaultValue: '1' }]); 1408e41f4b71Sopenharmony_ci``` 1409e41f4b71Sopenharmony_ci 1410e41f4b71Sopenharmony_ci 1411e41f4b71Sopenharmony_ci### keys<sup>10+</sup> 1412e41f4b71Sopenharmony_ci 1413e41f4b71Sopenharmony_cistatic keys(): Array<string> 1414e41f4b71Sopenharmony_ci 1415e41f4b71Sopenharmony_ciObtains an array of keys for all persistent attributes. 1416e41f4b71Sopenharmony_ci 1417e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1418e41f4b71Sopenharmony_ci 1419e41f4b71Sopenharmony_ci**Return value** 1420e41f4b71Sopenharmony_ci 1421e41f4b71Sopenharmony_ci| Type | Description | 1422e41f4b71Sopenharmony_ci| ------------------- | ---------------------------------- | 1423e41f4b71Sopenharmony_ci| Array<string> | Array of keys of all persistent attributes.| 1424e41f4b71Sopenharmony_ci 1425e41f4b71Sopenharmony_ci**Example** 1426e41f4b71Sopenharmony_ci```ts 1427e41f4b71Sopenharmony_cilet keys: Array<string> = PersistentStorage.keys(); 1428e41f4b71Sopenharmony_ci``` 1429e41f4b71Sopenharmony_ci 1430e41f4b71Sopenharmony_ci 1431e41f4b71Sopenharmony_ci### PersistProp<sup>(deprecated)</sup> 1432e41f4b71Sopenharmony_ci 1433e41f4b71Sopenharmony_cistatic PersistProp<T>(key: string, defaultValue: T): void 1434e41f4b71Sopenharmony_ci 1435e41f4b71Sopenharmony_ciPersists the attribute with the specified key in AppStorage to a file. This API is usually called before access to AppStorage. 1436e41f4b71Sopenharmony_ci 1437e41f4b71Sopenharmony_ciThe sequence of determining the type and value of an attribute is as follows: 1438e41f4b71Sopenharmony_ci 1439e41f4b71Sopenharmony_ci1. 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. 1440e41f4b71Sopenharmony_ci 1441e41f4b71Sopenharmony_ci2. 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. 1442e41f4b71Sopenharmony_ci 1443e41f4b71Sopenharmony_ci3. If no matching attribute is found in AppStorage, it is created in AppStorage, initialized with the value of **defaultValue**, and persisted. 1444e41f4b71Sopenharmony_ci 1445e41f4b71Sopenharmony_ciAccording 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 nonpersistent. 1446e41f4b71Sopenharmony_ci 1447e41f4b71Sopenharmony_ci 1448e41f4b71Sopenharmony_ci> **NOTE** 1449e41f4b71Sopenharmony_ci> 1450e41f4b71Sopenharmony_ci> This API is deprecated since API version 10. You are advised to use [persistProp10+](#persistprop10) instead. 1451e41f4b71Sopenharmony_ci 1452e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1453e41f4b71Sopenharmony_ci 1454e41f4b71Sopenharmony_ci**Parameters** 1455e41f4b71Sopenharmony_ci 1456e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1457e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ------------------------------------------------------------ | 1458e41f4b71Sopenharmony_ci| key | string | Yes | Attribute name. | 1459e41f4b71Sopenharmony_ci| defaultValue | T | Yes | Default value used to initialize the created attribute. The value cannot be **undefined** or **null**.| 1460e41f4b71Sopenharmony_ci 1461e41f4b71Sopenharmony_ci 1462e41f4b71Sopenharmony_ci**Example** 1463e41f4b71Sopenharmony_ci 1464e41f4b71Sopenharmony_ci 1465e41f4b71Sopenharmony_ci```ts 1466e41f4b71Sopenharmony_ciPersistentStorage.PersistProp('highScore', '0'); 1467e41f4b71Sopenharmony_ci``` 1468e41f4b71Sopenharmony_ci 1469e41f4b71Sopenharmony_ci 1470e41f4b71Sopenharmony_ci### DeleteProp<sup>(deprecated)</sup> 1471e41f4b71Sopenharmony_ci 1472e41f4b71Sopenharmony_cistatic DeleteProp(key: string): void 1473e41f4b71Sopenharmony_ci 1474e41f4b71Sopenharmony_ciPerforms the reverse operation of **PersistProp**. Specifically, this API deletes the attribute corresponding to the specified key from PersistentStorage. Subsequent AppStorage operations do not affect data in PersistentStorage. 1475e41f4b71Sopenharmony_ci 1476e41f4b71Sopenharmony_ci 1477e41f4b71Sopenharmony_ci> **NOTE** 1478e41f4b71Sopenharmony_ci> 1479e41f4b71Sopenharmony_ci> This API is deprecated since API version 10. You are advised to use [deleteProp10+](#deleteprop10) instead. 1480e41f4b71Sopenharmony_ci 1481e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1482e41f4b71Sopenharmony_ci 1483e41f4b71Sopenharmony_ci**Parameters** 1484e41f4b71Sopenharmony_ci 1485e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1486e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ----------------------- | 1487e41f4b71Sopenharmony_ci| key | string | Yes | Attribute name in PersistentStorage.| 1488e41f4b71Sopenharmony_ci 1489e41f4b71Sopenharmony_ci**Example** 1490e41f4b71Sopenharmony_ci```ts 1491e41f4b71Sopenharmony_ciPersistentStorage.DeleteProp('highScore'); 1492e41f4b71Sopenharmony_ci``` 1493e41f4b71Sopenharmony_ci 1494e41f4b71Sopenharmony_ci 1495e41f4b71Sopenharmony_ci### PersistProps<sup>(deprecated)</sup> 1496e41f4b71Sopenharmony_ci 1497e41f4b71Sopenharmony_cistatic PersistProps(properties: {key: string, defaultValue: any;}[]): void 1498e41f4b71Sopenharmony_ci 1499e41f4b71Sopenharmony_ciWorks 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. 1500e41f4b71Sopenharmony_ci 1501e41f4b71Sopenharmony_ci> **NOTE** 1502e41f4b71Sopenharmony_ci> 1503e41f4b71Sopenharmony_ci> This API is deprecated since API version 10. You are advised to use [persistProps10+](#persistprops10) instead. 1504e41f4b71Sopenharmony_ci 1505e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1506e41f4b71Sopenharmony_ci 1507e41f4b71Sopenharmony_ci**Parameters** 1508e41f4b71Sopenharmony_ci 1509e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1510e41f4b71Sopenharmony_ci| ---------- | ---------------------------------- | ---- | ------------------------------------------------------------ | 1511e41f4b71Sopenharmony_ci| 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**.| 1512e41f4b71Sopenharmony_ci 1513e41f4b71Sopenharmony_ci**Example** 1514e41f4b71Sopenharmony_ci 1515e41f4b71Sopenharmony_ci```ts 1516e41f4b71Sopenharmony_ciPersistentStorage.PersistProps([{ key: 'highScore', defaultValue: '0' }, { key: 'wightScore', defaultValue: '1' }]); 1517e41f4b71Sopenharmony_ci``` 1518e41f4b71Sopenharmony_ci 1519e41f4b71Sopenharmony_ci 1520e41f4b71Sopenharmony_ci### Keys<sup>(deprecated)</sup> 1521e41f4b71Sopenharmony_ci 1522e41f4b71Sopenharmony_cistatic Keys(): Array<string> 1523e41f4b71Sopenharmony_ci 1524e41f4b71Sopenharmony_ciObtains an array of keys for all persistent attributes. 1525e41f4b71Sopenharmony_ci 1526e41f4b71Sopenharmony_ci> **NOTE** 1527e41f4b71Sopenharmony_ci> 1528e41f4b71Sopenharmony_ci> This API is deprecated since API version 10. You are advised to use [keys10+](#keys10-1) instead. 1529e41f4b71Sopenharmony_ci 1530e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1531e41f4b71Sopenharmony_ci 1532e41f4b71Sopenharmony_ci**Return value** 1533e41f4b71Sopenharmony_ci 1534e41f4b71Sopenharmony_ci| Type | Description | 1535e41f4b71Sopenharmony_ci| ------------------- | ---------------------------------- | 1536e41f4b71Sopenharmony_ci| Array<string> | Array of keys of all persistent attributes.| 1537e41f4b71Sopenharmony_ci 1538e41f4b71Sopenharmony_ci**Example** 1539e41f4b71Sopenharmony_ci```ts 1540e41f4b71Sopenharmony_cilet keys: Array<string> = PersistentStorage.Keys(); 1541e41f4b71Sopenharmony_ci``` 1542e41f4b71Sopenharmony_ci 1543e41f4b71Sopenharmony_ci 1544e41f4b71Sopenharmony_ci## Environment 1545e41f4b71Sopenharmony_ci 1546e41f4b71Sopenharmony_ci 1547e41f4b71Sopenharmony_ciFor details about how to use Environment, see [Environment: Device Environment Query](../../../quick-start/arkts-environment.md). 1548e41f4b71Sopenharmony_ci 1549e41f4b71Sopenharmony_ci### EnvPropsOptions 1550e41f4b71Sopenharmony_ci 1551e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1552e41f4b71Sopenharmony_ci 1553e41f4b71Sopenharmony_ci**Parameters** 1554e41f4b71Sopenharmony_ci 1555e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1556e41f4b71Sopenharmony_ci| ------------ | --------------------------- | ---- | ------------------------------------------------------------ | 1557e41f4b71Sopenharmony_ci| key | string | Yes | Environment variable name. For details about the value range, see [Built-in Environment Variables](#built-in-environment-variables).| 1558e41f4b71Sopenharmony_ci| defaultValue | number \| string \| boolean | Yes | Default value used if the value of the environment variable key is not found in AppStorage.| 1559e41f4b71Sopenharmony_ci 1560e41f4b71Sopenharmony_ci 1561e41f4b71Sopenharmony_ci### envProp<sup>10+</sup> 1562e41f4b71Sopenharmony_ci 1563e41f4b71Sopenharmony_cistatic envProp<S>(key: string, value: S): boolean 1564e41f4b71Sopenharmony_ci 1565e41f4b71Sopenharmony_ciSaves 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. 1566e41f4b71Sopenharmony_ci 1567e41f4b71Sopenharmony_ciYou are advised to call this API when the application is started. 1568e41f4b71Sopenharmony_ci 1569e41f4b71Sopenharmony_ciIt is incorrect to use AppStorage to read environment variables without invoking **envProp** first. 1570e41f4b71Sopenharmony_ci 1571e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1572e41f4b71Sopenharmony_ci 1573e41f4b71Sopenharmony_ci**Parameters** 1574e41f4b71Sopenharmony_ci 1575e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 1576e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ | 1577e41f4b71Sopenharmony_ci| key | string | Yes | Environment variable name. For details about the value range, see [Built-in Environment Variables](#built-in-environment-variables).| 1578e41f4b71Sopenharmony_ci| value | S | Yes | Default value used if the value of the environment variable key is not found in AppStorage.| 1579e41f4b71Sopenharmony_ci 1580e41f4b71Sopenharmony_ci**Return value** 1581e41f4b71Sopenharmony_ci 1582e41f4b71Sopenharmony_ci| Type | Description | 1583e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 1584e41f4b71Sopenharmony_ci| boolean | Returns **false** if the attribute corresponding to the key exists in AppStorage; creates an attribute with the key and the default value and returns **true** otherwise.| 1585e41f4b71Sopenharmony_ci 1586e41f4b71Sopenharmony_ci**Example** 1587e41f4b71Sopenharmony_ci 1588e41f4b71Sopenharmony_ci 1589e41f4b71Sopenharmony_ciFor details about how to use **envProp**, see [Accessing Environment Parameters from UI](../../../quick-start/arkts-environment.md#accessing-environment-parameters-from-ui). 1590e41f4b71Sopenharmony_ci 1591e41f4b71Sopenharmony_ci 1592e41f4b71Sopenharmony_ci### envProps<sup>10+</sup> 1593e41f4b71Sopenharmony_ci 1594e41f4b71Sopenharmony_cistatic envProps(props: EnvPropsOptions[]): void 1595e41f4b71Sopenharmony_ci 1596e41f4b71Sopenharmony_ciWorks in a way similar to the [envProp](#envprop10) 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. 1597e41f4b71Sopenharmony_ci 1598e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1599e41f4b71Sopenharmony_ci 1600e41f4b71Sopenharmony_ci**Parameters** 1601e41f4b71Sopenharmony_ci 1602e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 1603e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ------------------------------------ | 1604e41f4b71Sopenharmony_ci| props | [EnvPropsOptions](#envpropsoptions)[] | Yes | Array of key-value pairs consisting of system environment variables and default values.| 1605e41f4b71Sopenharmony_ci 1606e41f4b71Sopenharmony_ci**Example** 1607e41f4b71Sopenharmony_ci```ts 1608e41f4b71Sopenharmony_ciEnvironment.envProps([{ key: 'accessibilityEnabled', defaultValue: 'default' }, { 1609e41f4b71Sopenharmony_ci key: 'languageCode', 1610e41f4b71Sopenharmony_ci defaultValue: 'en' 1611e41f4b71Sopenharmony_ci}, { key: 'prop', defaultValue: 'hhhh' }]); 1612e41f4b71Sopenharmony_ci``` 1613e41f4b71Sopenharmony_ci 1614e41f4b71Sopenharmony_ci 1615e41f4b71Sopenharmony_ci### keys<sup>10+</sup> 1616e41f4b71Sopenharmony_ci 1617e41f4b71Sopenharmony_cistatic keys(): Array<string> 1618e41f4b71Sopenharmony_ci 1619e41f4b71Sopenharmony_ciArray of keys of environment variables. 1620e41f4b71Sopenharmony_ci 1621e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1622e41f4b71Sopenharmony_ci 1623e41f4b71Sopenharmony_ci**Return value** 1624e41f4b71Sopenharmony_ci 1625e41f4b71Sopenharmony_ci| Type | Description | 1626e41f4b71Sopenharmony_ci| ------------------- | ----------- | 1627e41f4b71Sopenharmony_ci| Array<string> | Returns an array of associated system attributes.| 1628e41f4b71Sopenharmony_ci 1629e41f4b71Sopenharmony_ci**Example** 1630e41f4b71Sopenharmony_ci```ts 1631e41f4b71Sopenharmony_ciEnvironment.envProps([{ key: 'accessibilityEnabled', defaultValue: 'default' }, { 1632e41f4b71Sopenharmony_ci key: 'languageCode', 1633e41f4b71Sopenharmony_ci defaultValue: 'en' 1634e41f4b71Sopenharmony_ci}, { key: 'prop', defaultValue: 'hhhh' }]); 1635e41f4b71Sopenharmony_ci 1636e41f4b71Sopenharmony_cilet keys: Array<string> = Environment.keys(); // accessibilityEnabled, languageCode, prop 1637e41f4b71Sopenharmony_ci``` 1638e41f4b71Sopenharmony_ci 1639e41f4b71Sopenharmony_ci 1640e41f4b71Sopenharmony_ci### EnvProp<sup>(deprecated)</sup> 1641e41f4b71Sopenharmony_ci 1642e41f4b71Sopenharmony_cistatic EnvProp<S>(key: string, value: S): boolean 1643e41f4b71Sopenharmony_ci 1644e41f4b71Sopenharmony_ciSaves 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. 1645e41f4b71Sopenharmony_ci 1646e41f4b71Sopenharmony_ciYou are advised to call this API when the application is started. 1647e41f4b71Sopenharmony_ci 1648e41f4b71Sopenharmony_ciIt is incorrect to use AppStorage to read environment variables without invoking **EnvProp** first. 1649e41f4b71Sopenharmony_ci 1650e41f4b71Sopenharmony_ci> **NOTE** 1651e41f4b71Sopenharmony_ci> 1652e41f4b71Sopenharmony_ci> This API is deprecated since API version 10. You are advised to use [envProp10+](#envprop10) instead. 1653e41f4b71Sopenharmony_ci 1654e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1655e41f4b71Sopenharmony_ci 1656e41f4b71Sopenharmony_ci**Parameters** 1657e41f4b71Sopenharmony_ci 1658e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 1659e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ | 1660e41f4b71Sopenharmony_ci| key | string | Yes | Environment variable name. For details about the value range, see [Built-in Environment Variables](#built-in-environment-variables).| 1661e41f4b71Sopenharmony_ci| value | S | Yes | Default value used if the value of the environment variable key is not found in AppStorage.| 1662e41f4b71Sopenharmony_ci 1663e41f4b71Sopenharmony_ci**Return value** 1664e41f4b71Sopenharmony_ci 1665e41f4b71Sopenharmony_ci| Type | Description | 1666e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 1667e41f4b71Sopenharmony_ci| boolean | Returns **false** if the attribute corresponding to the key exists in AppStorage; creates an attribute with the key and the default value and returns **true** otherwise.| 1668e41f4b71Sopenharmony_ci 1669e41f4b71Sopenharmony_ci**Example** 1670e41f4b71Sopenharmony_ci 1671e41f4b71Sopenharmony_ci 1672e41f4b71Sopenharmony_ci```ts 1673e41f4b71Sopenharmony_ciEnvironment.EnvProp('accessibilityEnabled', 'default'); 1674e41f4b71Sopenharmony_ci``` 1675e41f4b71Sopenharmony_ci 1676e41f4b71Sopenharmony_ci 1677e41f4b71Sopenharmony_ci### EnvProps<sup>(deprecated)</sup> 1678e41f4b71Sopenharmony_ci 1679e41f4b71Sopenharmony_cistatic EnvProps(props: {key: string; defaultValue: any;}[]): void 1680e41f4b71Sopenharmony_ci 1681e41f4b71Sopenharmony_ciWorks in a way similar to the [EnvProp](#envpropdeprecated) 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. 1682e41f4b71Sopenharmony_ci 1683e41f4b71Sopenharmony_ci> **NOTE** 1684e41f4b71Sopenharmony_ci> 1685e41f4b71Sopenharmony_ci> This API is deprecated since API version 10. You are advised to use [envProps10+](#envprops10) instead. 1686e41f4b71Sopenharmony_ci 1687e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1688e41f4b71Sopenharmony_ci 1689e41f4b71Sopenharmony_ci**Parameters** 1690e41f4b71Sopenharmony_ci 1691e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 1692e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------- | ---- | ------------------------------------ | 1693e41f4b71Sopenharmony_ci| props | {key: string, defaultValue: any}[] | Yes | Array of key-value pairs consisting of system environment variables and default values.| 1694e41f4b71Sopenharmony_ci 1695e41f4b71Sopenharmony_ci**Example** 1696e41f4b71Sopenharmony_ci```ts 1697e41f4b71Sopenharmony_ciEnvironment.EnvProps([{ key: 'accessibilityEnabled', defaultValue: 'default' }, { 1698e41f4b71Sopenharmony_ci key: 'languageCode', 1699e41f4b71Sopenharmony_ci defaultValue: 'en' 1700e41f4b71Sopenharmony_ci}, { key: 'prop', defaultValue: 'hhhh' }]); 1701e41f4b71Sopenharmony_ci``` 1702e41f4b71Sopenharmony_ci 1703e41f4b71Sopenharmony_ci 1704e41f4b71Sopenharmony_ci### Keys<sup>(deprecated)</sup> 1705e41f4b71Sopenharmony_ci 1706e41f4b71Sopenharmony_cistatic Keys(): Array<string> 1707e41f4b71Sopenharmony_ci 1708e41f4b71Sopenharmony_ciArray of keys of environment variables. 1709e41f4b71Sopenharmony_ci 1710e41f4b71Sopenharmony_ci> **NOTE** 1711e41f4b71Sopenharmony_ci> 1712e41f4b71Sopenharmony_ci> This API is deprecated since API version 10. You are advised to use [keys10+](#keys10-2) instead. 1713e41f4b71Sopenharmony_ci 1714e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1715e41f4b71Sopenharmony_ci 1716e41f4b71Sopenharmony_ci**Return value** 1717e41f4b71Sopenharmony_ci 1718e41f4b71Sopenharmony_ci| Type | Description | 1719e41f4b71Sopenharmony_ci| ------------------- | ----------- | 1720e41f4b71Sopenharmony_ci| Array<string> | Returns an array of associated system attributes.| 1721e41f4b71Sopenharmony_ci 1722e41f4b71Sopenharmony_ci**Example** 1723e41f4b71Sopenharmony_ci 1724e41f4b71Sopenharmony_ci```ts 1725e41f4b71Sopenharmony_ciEnvironment.EnvProps([{ key: 'accessibilityEnabled', defaultValue: 'default' }, { 1726e41f4b71Sopenharmony_ci key: 'languageCode', 1727e41f4b71Sopenharmony_ci defaultValue: 'en' 1728e41f4b71Sopenharmony_ci}, { key: 'prop', defaultValue: 'hhhh' }]); 1729e41f4b71Sopenharmony_ci 1730e41f4b71Sopenharmony_cilet keys: Array<string> = Environment.Keys(); // accessibilityEnabled, languageCode, prop 1731e41f4b71Sopenharmony_ci``` 1732e41f4b71Sopenharmony_ci 1733e41f4b71Sopenharmony_ci 1734e41f4b71Sopenharmony_ci## Built-in Environment Variables 1735e41f4b71Sopenharmony_ci 1736e41f4b71Sopenharmony_ci| key | Type | Description | 1737e41f4b71Sopenharmony_ci| -------------------- | --------------- | ------------------------------------------------------------ | 1738e41f4b71Sopenharmony_ci| accessibilityEnabled | string | Whether to enable accessibility. If there is no value of **accessibilityEnabled** in the environment variables, the default value passed through APIs such as **envProp** and **envProps** is added to AppStorage.| 1739e41f4b71Sopenharmony_ci| colorMode | ColorMode | Color mode. The options are as follows:<br>- **ColorMode.LIGHT**: light mode.<br>- **ColorMode.DARK**: dark mode.| 1740e41f4b71Sopenharmony_ci| fontScale | number | Font scale. | 1741e41f4b71Sopenharmony_ci| fontWeightScale | number | Font weight scale. | 1742e41f4b71Sopenharmony_ci| layoutDirection | LayoutDirection | Layout direction. The options are as follows:<br>- **LayoutDirection.LTR**: from left to right.<br>- **LayoutDirection.RTL**: from right to left.| 1743e41f4b71Sopenharmony_ci| languageCode | string | Current system language. The value is in lowercase, for example, **zh**. | 1744