未验证 提交 ed738411 编写于 作者: O openharmony_ci 提交者: Gitee

!15603 [挑单Beta5】#I6INL9 +PR15251

Merge pull request !15603 from Annie_wang/cherry-pick-1678181205
...@@ -24,7 +24,7 @@ Obtain a **Preferences** instance for data operations. A **Preferences** instanc ...@@ -24,7 +24,7 @@ Obtain a **Preferences** instance for data operations. A **Preferences** instanc
**Table 1** API for obtaining a **Preferences** instance **Table 1** API for obtaining a **Preferences** instance
| Package | API | Description | | Bundle Name | API | Description |
| --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| ohos.data.preferences | getPreferences(context: Context, name: string): Promise\<Preferences> | Obtains a **Preferences** instance.| | ohos.data.preferences | getPreferences(context: Context, name: string): Promise\<Preferences> | Obtains a **Preferences** instance.|
...@@ -75,7 +75,7 @@ You can use the following APIs to delete a **Preferences** instance or data file ...@@ -75,7 +75,7 @@ You can use the following APIs to delete a **Preferences** instance or data file
**Table 6** APIs for deleting **Preferences** **Table 6** APIs for deleting **Preferences**
| Package | API | Description | | Bundle Name | API | Description |
| --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| ohos.data.preferences | deletePreferences(context: Context, name: string): Promise\<void> | Deletes a **Preferences** instance from the memory and its files from the device.| | ohos.data.preferences | deletePreferences(context: Context, name: string): Promise\<void> | Deletes a **Preferences** instance from the memory and its files from the device.|
| ohos.data.preferences | removePreferencesFromCache(context: Context, name: string): Promise\<void> | Removes a **Preferences** instance from the memory to release memory. | | ohos.data.preferences | removePreferencesFromCache(context: Context, name: string): Promise\<void> | Removes a **Preferences** instance from the memory to release memory. |
...@@ -113,22 +113,20 @@ You can use the following APIs to delete a **Preferences** instance or data file ...@@ -113,22 +113,20 @@ You can use the following APIs to delete a **Preferences** instance or data file
```ts ```ts
// Obtain the context. // Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility' import UIAbility from '@ohos.app.ability.UIAbility';
let context = null;
let preferences = null; let preferences = null;
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage) {
context = this.context; let promise = data_preferences.getPreferences(this.context, 'mystore');
}
}
let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((pref) => { promise.then((pref) => {
preferences = pref; preferences = pref;
}).catch((err) => { }).catch((err) => {
console.info("Failed to get the preferences."); console.info("Failed to get the preferences.");
}) })
}
}
``` ```
3. Write data. 3. Write data.
......
...@@ -22,8 +22,8 @@ import data_preferences from '@ohos.data.preferences'; ...@@ -22,8 +22,8 @@ import data_preferences from '@ohos.data.preferences';
| Name | Type| Readable| Writable| Description | | Name | Type| Readable| Writable| Description |
| ---------------- | -------- | ---- | ---- | --------------------------------------- | | ---------------- | -------- | ---- | ---- | --------------------------------------- |
| MAX_KEY_LENGTH | number | Yes | No | Maximum length of a key. The key must be less than 80 bytes. | | MAX_KEY_LENGTH | number | Yes | No | Maximum length of a key. The maximum key length is 80 bytes. |
| MAX_VALUE_LENGTH | number | Yes | No | Maximum length of a value. The value must be less than 8192 bytes.| | MAX_VALUE_LENGTH | number | Yes | No | Maximum length of a value. The maximum value length is 8192 bytes.|
## data_preferences.getPreferences ## data_preferences.getPreferences
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册