gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 13:25:48 24 4
gpt4 key购买 nike

我已经阅读了 Jetpack 的新库(现在处于 alpha 版本)-Jetpack Datastore .
从文档中可以清楚地看出它是一种 Shared Preferences' killer

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

DataStore uses Kotlin coroutines and Flow to store dataasynchronously, consistently, and transactionally

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


如果我没有错过任何东西,你就不能在 Java 中使用这个库。我对吗?我个人使用 Kotlin,但对我来说,这是 AndroidX 库的一个特殊先例。

最佳答案

2021 年 1 月 13 日
Version 1.0.0-alpha06被释放。添加了对 RxJava 2/3 的支持,因此现在可以在 Java 中使用 Datastore。

Added RxJava wrappers for DataStore. The datastore-rxjava2/3 artifactscontain the wrappers for the core DataStore APIs (RxDataStore,RxDataStoreBuilder, and RxDataMigration). Thedatastore-preferences-rxjava2/3 artifacts contain a builder toconstruct a Preferences DataStore.


为此,您应该添加依赖项:
// optional - RxJava2 support
implementation "androidx.datastore:datastore-rxjava2:1.0.0-alpha06"

// optional - RxJava3 support
implementation "androidx.datastore:datastore-rxjava3:1.0.0-alpha06"
另外现在 Datastore's official documentation包含 Java 的代码示例的等价物。

关于java - 新的 Jetpack 数据存储仅适用于 Kotlin 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64036701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com