新的Jetpack数据存储区仅适用于Kotlin吗?

2019年8月20日 32点热度 0条评论

我已经从Jetpack(现在是Alpha版)中阅读了有关新库的信息-Jetpack Datastore
从文档中可以明显看出,这是一种Shared Preferences' killer

Jetpack DataStore is a data storage solution that allows you to store key-value pairs or typed objects with protocol buffers

DataStore uses Kotlin coroutines and Flow to store data asynchronously, consistently, and transactionally

If you're currently using SharedPreferences to store data, consider migrating to DataStore instead

如果我什么都没错过,那么您将无法在Java中使用此库。我对吗?我个人使用Kotlin,但对我来说,这是AndroidX库的一个特殊先例。

解决方案如下:

我很确定他们不打算使用Java。

Built on Kotlin coroutines and Flow, DataStore provides two different implementations: Proto DataStore, that lets you store typed objects (backed by protocol buffers) and Preferences DataStore, that stores key-value pairs. Data is stored asynchronously, consistently, and transactionally, overcoming most of the drawbacks of SharedPreferences.

就我而言,Kotlin协程/流程不适用于Java。

您可以阅读更多
here,这是Florina的精彩文章。