Search code examples
androiddatabasewear-osandroid-wear-data-api

How To Sync Old Data From DataAPI To Wearable


I am currently getting a list of data from a URL on the handheld device, and passing this list as a string array to the Data Layer. Now, I understand that I can use onDataChanged() within the DataListener to get the data from the Data Layer on the wearable. But you can only retrieve this data when it is updated. How would I go about retrieving this data even if it is not updated? Does the Data Layer even store the data for extended periods? Or should I be storing this data in say an SQL Database on the wearable? Or should I be forcing this data to be wiped (and then refreshed) upon opening the wearable app, so that it is always updated when it opens?


Solution

  • Unless you delete a data item, system will not remove it (and that is why it is a good idea to delete the ones that you know you wouldn't be needing, to save space). You can get the existing data items by calling DataApi#getDataItems; the variant that takes a filter is more appropriate since it allows you to narrow down on the items you are really interested in.