【问题标题】:WearableListenerService binding/unbinding continuouslyWearableListenerService不断绑定/解绑
【发布时间】:2017-01-10 21:35:04
【问题描述】:

我制作了一个简单的智能手表应用程序,可以连接到手机以发送一些数据。但是,它会不断地绑定和解除绑定,从而导致很多延迟。 Logcat 展示

01-10 22:26:17.780 13094-17893/com.verbraeken.joost V/WearableLS: bindService:  com.verbraeken.joost/.WearListenerService
01-10 22:26:17.783 13094-17893/com.verbraeken.joost V/WearableLS: unbindService: com.verbraeken.joost/.WearListenerService

在清单中,服务声明为:

<service android:name="WearListenerService">
  <intent-filter>
    <action android:name="com.google.android.gms.wearable.DATA_CHANGED"/>
    <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED"/>
    <action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED"/>
    <action android:name="com.google.android.gms.wearable.CHANNEL_EVENT"/>
    <data android:path="/WEAR_ORIENTATION" android:host="*" android:scheme="wear"/>
  </intent-filter>
</service>

服务本身确实扩展了 WearableListenerService 并且只有一个 onMessageReceived 方法。

服务每秒绑定/取消绑定大约 50 次的原因可能是什么?

【问题讨论】:

  • 哪款索尼智能手表?
  • 索尼智能手表 3

标签: android service wear-os sony-smartwatch


【解决方案1】:

这是服务的默认行为(绑定和取消绑定),基于文档 - Sending and Syncing Data:

WearableListenerService(用于服务)

扩展WearableListenerService 可让您侦听服务中的重要数据层事件。系统管理WearableListenerService的生命周期,在需要发送数据项或消息时绑定到服务,在不需要工作时取消绑定服务

请检查您的实现,以验证您遇到的错误(每秒绑定/取消绑定 x 次)。

希望这会有所帮助。

【讨论】:

  • 感谢您的帮助!有没有办法让服务被绑定,直到我告诉它解除绑定?
猜你喜欢
  • 2012-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-07
  • 2021-11-02
  • 2020-03-22
相关资源
最近更新 更多