From 05383f1ba3298c20c97a3976ed303016c3a6e9f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Sat, 25 Feb 2012 22:52:52 +0100 Subject: Send messages correctly. --- same-android/src/main/java/com/orbekk/same/SameService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'same-android/src') diff --git a/same-android/src/main/java/com/orbekk/same/SameService.java b/same-android/src/main/java/com/orbekk/same/SameService.java index 53742bd..55fb17c 100644 --- a/same-android/src/main/java/com/orbekk/same/SameService.java +++ b/same-android/src/main/java/com/orbekk/same/SameService.java @@ -111,10 +111,19 @@ public class SameService extends Service { private StateChangedListener stateListener = new StateChangedListener() { @Override public void stateChanged(Component component) { + ArrayList dropped = new ArrayList(); for (Messenger messenger : stateReceivers) { Message message = Message.obtain(null, UPDATED_STATE_MESSAGE); message.obj = component; + try { + messenger.send(message); + } catch (RemoteException e) { + logger.warn("Failed to send update. Dropping state receiver."); + e.printStackTrace(); + dropped.add(messenger); + } } + stateReceivers.removeAll(dropped); } }; @@ -168,6 +177,8 @@ public class SameService extends Service { try { sameController.start(); sameController.getClient().setNetworkListener(networkListener); + sameController.getClient().getInterface() + .addStateListener(stateListener); } catch (Exception e) { logger.error("Failed to start server", e); } -- cgit v1.2.3