I am just getting started on developing an Android Wear companion app for my handheld application. I have been going through the developer documents, and I am looking to get data from the handheld to view on the wearable. I am looking to use a listener activity that implements DataApi.DataListener
to get data from the handheld device, shown here: Handling Data Layer Events. In my case, the wearable is only getting data from the handheld, never the reverse. As it says under the heading With a WearableListenerService:
...you can have a handheld app that sets and gets data item objects and a wearable app that listens for these updates to update it's UI. The wearable never updates any of the data items, so the handheld app doesn't listen for any data events from the wearable app.
The handheld does not need to listen for data events from the wearable, so what kind of service or otherwise would I use to get and set data on the handheld to receive on the wearable? I would like to be able to get data from the handheld at any time, even if the handheld application is closed, and if the device is locked. This data would be data I would be obtaining from a server, and possibly location data of the user as well. I also would like to be able to update this data when the wearable application is opened (or on a button press). So would I need to implement a listener service on the handheld as well, just to get information on when the wearable application is opened?
Yes, you need to. Whether the handheld application is running or not, you cannot "request" anything from it, from the wearable device, unless either (1) you send some sort of message from your wearable device to it to let it know that you are expecting some data, or (2) the handheld device periodically sends data on its own without being asked. The second approach is not good since you don't want to have that kind of data transmission happening constantly (and even if in background through a service); that hurts your phone and watch's battery severely. For the first approach, the handheld application should have a listener so it can learn about incoming messages fro the watch. If your handheld device needs to response to those requests only if it is in the foreground and running, then you can just register a DataListener in your activity. But if you want to be able to respond to such requests even if your app is not in front or not even running, you'd need to have a WearableListenerService in your handheld app so that the framework can wake your app up and pass the message to it.