Skip to content

Unnecessary Iteration of Connected Nodes #1

@StuStirling

Description

@StuStirling

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");
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions