本文介绍了在每个 PutDataMapRequest 上调用 Wea​​rableListenerService onDataChanged()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 WearableListenerService 每次发出请求时都调用 onDataChanged().我知道 onDataChanged() 仅在数据更改时调用,而不是每次都调用.

I want WearableListenerService to call onDataChanged() every time I make a request. I am aware that onDataChanged() is only called, well, on data change and not every time.

我可以添加带有日期的虚拟数据来实现这一点,但这感觉不完整.

I can add dummy data with the date to make this happen, but that feels patchy.

有没有更优雅的方式来实现我想做的事情?

Is there a more elegant way to achieve what I want to do?

推荐答案

您或许可以稍微扭转局势.正如您所说,onDataChanged 仅在发生更改时调用,您可能应该继续处理.

You might be able to turn the situation around a bit. As you say, onDataChanged is only called whenever there's a change and you should probably keep handling that.

每当您需要知道当前值时,您都可以使用 Wearable.DataApi.getDataItem(s) 方法之一,如 https://developer.android.com/reference/com/google/android/gms/wearable/DataApi.html

Whenever you need to know the current value you can use one of the Wearable.DataApi.getDataItem(s) methods as described on https://developer.android.com/reference/com/google/android/gms/wearable/DataApi.html .

这篇关于在每个 PutDataMapRequest 上调用 Wea​​rableListenerService onDataChanged()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!