看啥推荐读物
专栏名称: 谷歌开发者
Google中国官方账号。汇集Android, Chrome, Angular等移动和网络开发技术、Google Play和AdMob等开发者成长、优化和变现平台。
今天看啥  ›  专栏  ›  谷歌开发者

使用 Jetpack DataStore 进行数据存储

谷歌开发者  · 公众号  · 科技媒体  · 2021-01-08 09:30
作者 / Android 开发技术推广工程师 Florina Muntenescu 与 Google 软件工程师 Rohit Sathyanarayana  欢迎使用 Jetpack DataStore,这是一个经过改进的全新数据存储解决方案,旨在替代原有的 SharedPreferences。Jetpack DataStore 基于 Kotlin 协程和 Flow 开发,并提供两种不同的实现: Proto DataStore 和 Preferences DataStore。其中 Proto DataStore,可以存储带有类型的对象 (使用 protocol buffers 实现);Preferences DataStore,可以存储键值对。在 DataStore 中,数据以异步的、一致的、事务性的方式进行存储,克服了 SharedPreferences 的大部分缺点。 protocol buffershttps://developers.google.cn/protocol-buffersSharedPreferences 和 DataStore 对比* SharedPreferences 有一个看上去可以在 UI 线程安全调用的同步 API,但是该 API 实际上执行了磁盘 I/O 操 ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照