AndroidStudy
AndroidStudy copied to clipboard
bug
private final Handler mHandler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message msg) { switch (msg.what) { case APPLE_INFO: Apple apple = (Apple) msg.obj; //观察者模式,通知所有客户端 final int clientNum = mCallbacks.beginBroadcast(); for (int i = 0; i < clientNum; i++) { IRemoteServiceCallBack callBack = mCallbacks.getBroadcastItem(i); if (callBack != null && apple != null) { try { callBack.noticeAppleInfo(apple); } catch (RemoteException e) { e.printStackTrace(); } } mCallbacks.finishBroadcast(); } break; } super.handleMessage(msg); } mCallbacks.finishBroadcast();应该放到for循环后面,不然通知一个就结束了