2

Please consider a scenario where some data is being transferred between a phone & watch app using DataClient and PutDataRequest. For simplicity, the data is just a string of "Hello".

val client = Wearable.getDataClient(context)

val data = "Hello".encodeToByteArray()

val request = PutDataRequest
        .create("path")
        .setUrgent()
        .setData(data)

client.putDataItem(request)

My go to solution for storing this on the wear side of things would be using DataStore.

But, DataClient has a similar API

client.getDataItem(uri) -> DataItem (which has the string)

Can i, should I, use this instead?

My requirements for the data will never change (it will always be stored as a string). Am I just duplicating the data by "also" storing it in the DataStore, when its already available through the DataClient?

I intend to use the data by loading it (and then observing changes to it) when the watch app is launched. I can do that using the DataClient in a similar manner that Id do it using DataStore.

Edit: I guess what Im also wondering is whether or not this is an effective way of storing the data. Does the DataClient API involve additional overhead when writing/reading data that I should be aware of, or is it as fast as DataStore?

zoltish
  • 2,122
  • 19
  • 37

1 Answers1

0

Operations on the DataClient are remote in that they are IPC calls to the GMS Core process. They could fail, and they can be delayed.

So if the data is essential, you may want to have a local DataStore caching the data, and updating in response to DataClient updates.

Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69