WearableListenerService只处理上的第二次尝试onMessageReceived() [英] WearableListenerService only handles onMessageReceived() on second try

查看:550
本文介绍了WearableListenerService只处理上的第二次尝试onMessageReceived()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Andr​​oid Wear演示来说明消息API。我捕捉输入上的手表并将其传递到手持设备的云处理,从而扩展WearableListenerService以下类是手机上运行:

I've got a simple Android Wear demo to illustrate the Message API. I'm capturing input on a watch and passing it off to a handheld device for cloud processing, so the following class that extends WearableListenerService is running on a phone:

public class ListenerService extends WearableListenerService {

    private static final String MESSAGE_PATH = "/handle-inbound-message";

    @Override
    public void onMessageReceived(MessageEvent messageEvent) {
        super.onMessageReceived(messageEvent);
        if(messageEvent.getPath().equals(MESSAGE_PATH)) {
            updateData(new String(messageEvent.getData()));
        }
    }

    private void updateData(final String volume) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                // do neat stuff with the inbound data
            }
        }).start();
    }
}

...和耐磨code生成消息,通过点击穿戴式应用的一个按钮的方式,就是像这样:

...and the wearable code generating the message, by way of clicking a button on the wearable app, is like so:

private void sendToHandheld(final byte[] volume) {
   if(nodeId != null) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                client.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
                Wearable.MessageApi.sendMessage(client, nodeId, MESSAGE_PATH, volume);
                client.disconnect();
            }
        }).start();
    }
}

在code正常工作......除了事实,我必须单击可穿戴应用按钮的两次以获得onMessageReceived()开火。该应用程序启动,但没有得到消息的第一次......与应用程序还开着,我再次点击按钮,它完美地触发。任何人都可以看到我可能犯了一个错误?

The code works fine...except for the fact that I have to click the button twice in the wearable app to get onMessageReceived() to fire. The app starts up, but doesn't get the message the first time...with the app still open, I click the button again and it fires perfectly. Can anyone see where I might have made a mistake?

(另外,我看到很多code的演示一个回购协议,人们不叫super.onMessageReceived()。)

(Also, I'm seeing a lot of code demos a repos where people don't call super.onMessageReceived().)

推荐答案

OK,我想我解决了这个问题 - 我注释掉在onM​​essageReceived(),其中超类被称为行了... ...和固定它。

OK, I think I solved the issue - I commented-out the line in onMessageReceived() where the superclass is called...and that fixed it.

成功!感谢您的帮助,先生们。 :)

SUCCESS! Thanks for your help, gents. :)

这篇关于WearableListenerService只处理上的第二次尝试onMessageReceived()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆