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

!15594 [翻译完成】#I6INHX

Merge pull request !15594 from Annie_wang/PR14960
...@@ -114,21 +114,19 @@ You can use the following APIs to delete a **Preferences** instance or data file ...@@ -114,21 +114,19 @@ 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');
promise.then((pref) => {
preferences = pref;
}).catch((err) => {
console.info("Failed to get the preferences.");
})
} }
} }
let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((pref) => {
preferences = pref;
}).catch((err) => {
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.
先完成此消息的编辑!
想要评论请 注册