diff --git a/en/application-dev/database/database-preference-guidelines.md b/en/application-dev/database/database-preference-guidelines.md index c440e385232bf3f3bb8c4aa3a7e254a5e6fc0d90..724e273675061c4b6969fb3fcd6f6cbdd984a15f 100644 --- a/en/application-dev/database/database-preference-guidelines.md +++ b/en/application-dev/database/database-preference-guidelines.md @@ -24,7 +24,7 @@ Obtain a **Preferences** instance for data operations. A **Preferences** instanc **Table 1** API for obtaining a **Preferences** instance -| Package | API | Description | +| Bundle Name | API | Description | | --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | ohos.data.preferences | getPreferences(context: Context, name: string): Promise\ | Obtains a **Preferences** instance.| @@ -75,7 +75,7 @@ You can use the following APIs to delete a **Preferences** instance or data file **Table 6** APIs for deleting **Preferences** -| Package | API | Description | +| Bundle Name | API | Description | | --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | ohos.data.preferences | deletePreferences(context: Context, name: string): Promise\ | Deletes a **Preferences** instance from the memory and its files from the device.| | ohos.data.preferences | removePreferencesFromCache(context: Context, name: string): Promise\ | 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 ```ts // Obtain the context. - import UIAbility from '@ohos.app.ability.UIAbility' - let context = null; + import UIAbility from '@ohos.app.ability.UIAbility'; let preferences = null; export default class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage){ - context = this.context; + onWindowStageCreate(windowStage) { + 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. @@ -200,6 +198,6 @@ You can use the following APIs to delete a **Preferences** instance or data file proDelete.then(() => { console.info("Deleted data successfully."); }).catch((err) => { - console.info("Failed to delete data. Cause: " + err); + console.info("Failed to delete data. Cause: " + err); }) ``` diff --git a/en/application-dev/reference/apis/js-apis-data-preferences.md b/en/application-dev/reference/apis/js-apis-data-preferences.md index de22c34d2a99d3e7391061cc9233089409944599..b14256c20d12c8fedd2bb6d8f0b7f38091bbc8d5 100644 --- a/en/application-dev/reference/apis/js-apis-data-preferences.md +++ b/en/application-dev/reference/apis/js-apis-data-preferences.md @@ -22,8 +22,8 @@ import data_preferences from '@ohos.data.preferences'; | 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_VALUE_LENGTH | number | Yes | No | Maximum length of a value. The value must be less than 8192 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 maximum value length is 8192 bytes.| ## data_preferences.getPreferences