Delay in Android Wear putDataItem() and invoking of onDataChanged()

269 views Asked by At

I want to use the action button "Open" on a notification on my Android Wear application, to open a Dialog with some task data on my handheld.
To do this, I put my message in a PutDataMapRequest and use the following method in my Wearable code:

PutDataMapRequest dataMap = PutDataMapRequest.create("/task/" + "1");

dataMap.getDataMap().putString(DataMapKeys.TASK_MESSAGE, message);
....
dataMap.getDataMap().putLong("timestamp", System.currentTimeMillis());

PutDataRequest putDataRequest = dataMap.asPutDataRequest();

Wearable.DataApi.putDataItem(googleApiClient, putDataRequest).setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
    @Override
    public void onResult(DataApi.DataItemResult dataItemResult) {
        Log.d(TAG, "Sending task data: " + dataItemResult.getStatus().isSuccess());
    }
});

And then, to catch it in my WearableListenerService on my handheld/mobile device:

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    Log.d(TAG, "Received task data, now opening dialog..");
}

However, there is a significant delay (about 10 seconds) between the call to onResult() in the putDataItem() method in my Wear app, and the invoking of the onDataChanged() method in my mobile app.
This means that when I press the "Open" Action button on the notification on my watch, the dialog opens about 10 seconds later on my phone.
I would like this to be instant, if possible.

Is this possible, or am I doing something wrong here in my code?

Best,

1

There are 1 answers

0
gruszczy On

Switch to using MessageApi. It is intended for situations like this: it doesn't have a guarantee of delivery (if the devices are not connected at the moment), but is fast. And clicking a button is exactly the situation where it should be used (because user can repeat it).