0

I'd like some high-level input on how I'm approaching a watch face I'm building as a teaching tool. It's quite simple - grabbing trending topics from Twitter once an hour and displaying them on the watch. Basically, my flow is as follows:

  1. I have an AlarmManager on the paired phone that polls the Twitter API and pulls down fresh data, set to fire a BroadcastReceiver
  2. When invoked, the BroadcastReceiver uses the Data Layer API to send a one-way message to the wearable containing the downloaded data
  3. Upon receipt, the wearable app saves the inbound data to SharedPreferences as a persistent data store and redraws the topics to the watch face from SharedPreferences

Presumably this all happens in the background, whether the watch face is actively being displayed or not.

I'm thinking alternatively I could also save the Twitter data to SharedPreferences on the phone app and then use more elegant Data Layer API syncing job between the phone and watch that's triggered when the watch face becomes visible. Or, running things on the wearable via the Lollipop JobScheduler API.

Anyone see any glaring areas I could design better? Thanks!

user2302078
  • 142
  • 1
  • 11

1 Answers1

1

Keep in mind, that Data API. already gives you persistence, so you don't need to involve SharedPreferences. The way you should approach this, is to use only Data API. Your phone is the producer of data items and the wearable is the consumer, which displays information based on what it receives in data items.

The way it works is like this:

  1. your phone fetches trends from Twitter;
  2. it goes through existing data items, deletes old ones and new ones;
  3. the watch face eventually receives the updates about the data items; it starts showing data from new ones and stops showing data from deleted ones;

You might also consider, what the watch face does when it starts. This is simple: it just reads all the existing data items and displays data based on them.

In general: if you store the data in the data items, you don't need to copy them to any other persistent storage. Data items are persistent storage that is shared between connected devices.

gruszczy
  • 40,948
  • 31
  • 128
  • 181
  • 1
    Good luck with your watch face :) – gruszczy Jan 19 '15 at 05:25
  • Actually @gruszczy, I was hoping you'd chime-in on something I ran into if you have time: http://stackoverflow.com/questions/28058284/using-data-api-changes-to-update-watch-face-ui – user2302078 Jan 21 '15 at 02:40