0

我正在使用 JetPack DataStore,因为我需要持久对象和原始类型。但我在从我的 protoDataStore 读取值时遇到问题。使用文档中的阅读方法(https://developer.android.com/topic/libraries/architecture/datastore#kotlin)。我总是在 protobuf 中获得存储数据的流。有没有办法返回一个 Int 值?例如:

  val exampleCounterFlow: Flow<Int> = context.settingsDataStore.data
  .map { settings ->
    // The exampleCounter property is generated from the proto schema.
    settings.exampleCounter
  }

有没有办法将 exampleCounter 存储在 Int 引用中?

Int exampleCounterReaded = valueOfexamplecounterReadedInFlow

提前致谢!

编辑:换句话说,我想重建存储的对象。

4

0 回答 0