# Preferences **Repository Path**: harmonyos_codelabs/Preferences ## Basic Information - **Project Name**: Preferences - **Description**: 基于首选项,实现对本地应用数据的访问及操作。 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 8 - **Forks**: 6 - **Created**: 2024-06-15 - **Last Updated**: 2025-11-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Preferences ### Introduction Learn to access and operate local application data based on preferences. The display effect is as follows: ![image](screenshots/device/preference.en.gif) ### Concepts - Preferences: a module that provides APIs for processing data in the form of key-value (KV) pairs, including querying, modifying, and persisting KV pairs. The key is a string, and the value can be a number, a string, a Boolean value, or an array of them. - TextInput: a component that provides single-line text input. - Button: a component used to quickly create buttons of different styles. ### Permissions N/A ### How to Use 1. In the Fruit and Number text boxes, enter the corresponding fruit name and quantity, and tap the **Write DB** button to save the entered data to the preferences. 2. Exit the app and open it again. The data saved last time is displayed in the Fruit and Number text boxes. 3. Tap the **Read DB** button. The data saved last time is displayed in the Fruit and Number text boxes. 4. Tap the **Delete DB File** button. The data in the Fruit and Number text boxes is cleared, and the data in the preferences and the corresponding database file is deleted. ### Constraints 1. The sample app is supported only on Huawei phones running the standard system. 2. HarmonyOS: HarmonyOS 5.0.5 Release or later 3. DevEco Studio: DevEco Studio 6.0.0 Release or later 4. HarmonyOS SDK: HarmonyOS 6.0.0 Release SDK or later