service - Android WearableListenerService has to be called twice to receive Message -
i'm sending message wear service handheld. first time i'm clicking button on handheld calling oncreate method of service, second time service receives message. can't figure out problem.
here wear part:
@override public void onclick(view v) { final pendingresult<nodeapi.getconnectednodesresult> nodes1 = wearable.nodeapi.getconnectednodes(mapiclient); nodes1.setresultcallback(new resultcallback<nodeapi.getconnectednodesresult>() { @override public void onresult(nodeapi.getconnectednodesresult result) { (int = 0; < result.getnodes().size(); i++) { node node = result.getnodes().get(i); pendingresult<messageapi.sendmessageresult> messageresult = wearable.messageapi.sendmessage(mapiclient, node.getid(), "/open;" + cnt, null); messageresult.setresultcallback(new resultcallback<messageapi.sendmessageresult>() { @override public void onresult(messageapi.sendmessageresult sendmessageresult) { status status = sendmessageresult.getstatus(); log.d("", "##status: " + status.tostring()); if (status.getstatuscode() != wearablestatuscodes.success) { //not getting there, success } } }); } } }); }
i have following wearablelistenerservice:
public class datalayerlistenerservice extends wearablelistenerservice implements connectioncallbacks, onconnectionfailedlistener { private googleapiclient mapiclient; private sharedpreferences prefs; @override public void oncreate() { log.d("", "##dataservice created"); super.oncreate(); if (null == mapiclient) { mapiclient = new googleapiclient.builder(this).addapi(wearable.api).addconnectioncallbacks(this).addonconnectionfailedlistener(this) .build(); } if (!mapiclient.isconnected()) { mapiclient.connect(); log.d("", "##api connecting"); } } @override public void ondestroy() { log.d("", "##dataservice destroyed"); if (null != mapiclient) { if (mapiclient.isconnected()) { mapiclient.disconnect(); } } super.ondestroy(); } @override public void onmessagereceived(messageevent messageevent) { log.d("", "##dataservice received " + messageevent.getpath()); super.onmessagereceived(messageevent); if (messageevent.getpath().contains("/open;")) { // if called twice :( } } @override public void ondatachanged(dataeventbuffer dataevents) { log.d("", "##dataservice data changed"); } @override public void onconnectionfailed(connectionresult arg0) { } @override public void onconnected(bundle arg0) { } @override public void onconnectionsuspended(int arg0) { } }
maybe should mention ony have click button twice when service gets destroyed before, happens seconds after click event. so..in fact happens:
wear click
service oncreate
wear click
service onmessagereceived
wear click
service onmessagereceived
//wait seconds
service ondestroy
wear click
service oncreate
wear click
service onmessagereceived
hope clear :-)
thanks in advance!!
i think may have solved phillip adam - try commenting-out line in service in onmessagereceived() method makes call superclass. holds me. :)
Comments
Post a Comment