LarkspurCA / WearableDataMap

Wearable Data Layer example for DataMap objects
15 stars 7 forks source link

Unnecessary Iteration of Connected Nodes #1

Open StuStirling opened 8 years ago

StuStirling commented 8 years ago

Hi,

I believe when you iterate over your nodes in the background thread that this is unnecessary.

Correct me if I'm wrong but I think there is a single DataApi instance that is shared across all nodes so if you make a change to the api once then all nodes connected would be notified through onDataChanged.

At the moment you're not using the Node for anything other than displaying the node's display name. It doesn't mean that that node has been updated however.

This is the code I'm talking about.

NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleClient).await();
        for (Node node : nodes.getNodes()) {

            // Construct a DataRequest and send over the data layer
            PutDataMapRequest putDMR = PutDataMapRequest.create(path);
            putDMR.getDataMap().putAll(dataMap);
            PutDataRequest request = putDMR.asPutDataRequest();
            DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleClient,request).await();
            if (result.getStatus().isSuccess()) {
                Log.v("myTag", "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
            } else {
                // Log an error
                Log.v("myTag", "ERROR: failed to send DataMap");
            }
        }
LarkspurCA commented 8 years ago

Good catch. I'll remove the node iteration from this example, and from the associated data layer chapter in androidweardocs.com