系列文章目录
1.HarmonyOS | 状态管理(一) | @State装饰器
2.HarmonyOS | 状态管理(二) | @Prop装饰器
3.HarmonyOS | 状态管理(三) | @Link装饰器
4.HarmonyOS | 状态管理(四) | @Provide和@Consume装饰器
5.HarmonyOS | 状态管理(五) | @Observed装饰器和@ObjectLink装饰器
6.HarmonyOS | 状态管理(六) | LocalStorage(页面级UI状态存储)
7.HarmonyOS | 状态管理(七) | AppStorage(应用级UI状态存储)
文章目录
前言
上一篇我们讲到了应用级UI状态存储(AppStorage),本篇我们来讲下持久化存储UI状态(PersistentStorage)
一、PersistentStorage的作用是什么?
PersistentStorage的作用是:应用退出再次启动后,依然能保存选定的结果。
二、PersistentStorage的特性
-
PersistentStorage将选定的AppStorage属性保留在设备磁盘上。
-
应用程序通过API,以决定哪些AppStorage属性应借助PersistentStorage持久化。
-
UI和业务逻辑不直接访问PersistentStorage中的属性,所有属性访问都是对AppStorage的访问,AppStorage中的更改会自动同步到PersistentStorage。
-
PersistentStorage和AppStorage中的属性建立双向同步。应用开发通常通过AppStorage访问PersistentStorage。
三、限制条件
Persiste