Define a Client Messenger associated with the Handler to receive the return from the server:
/** Target we publish for clients to send messages to IncomingHandler.*/finalMessengermMessenger=newMessenger(new IncomingHandler());/* * Start cellular network operator querying. * @param event the event you want to start, can be one of following: * 1 - EVENT_NETWORK_SCAN * 2 - EVENT_NETWORK_SELECT * @return mMessenger which associated with Handler.*/Messagemsg=Message.obtain(null,1/ event /,0/ slot */,0);msg.replyTo= mMessenger;mService.send(msg);/** Receive the return of the network operator's search interface:*/finalString[]scanInfo=msg.getData().getStringArray("result");for(inti=0; i <scanInfo.length; i++){Stringitem[]= scanInfo[i].split(",");StringoperatorAlphaLong= scanInfo0;// such as 'CHN-UNICOM'StringoperatorAlphaShort= scanInfo1;// such as 'UNICOM'StringoperatorNumeric= scanInfo2;// such as '46001'StringstateString= scanInfo3;// such as 'available/forbidden'}/** Set cellular network operator. * @paramevent the event you want to start, can be one of following: * 1 - EVENT_NETWORK_SCAN * 2 - EVENT_NETWORK_SELECT * @return mMessenger which associated with Handler.*/Bundlebundle=newBundle();bundle.putString("operatorAlphaLong", operatorAlphaLong);bundle.putString("operatorAlphaShort", operatorAlphaShort);bundle.putString("operatorNumeric", operatorNumeric);bundle.putString("stateString", stateString);Messagemsg=Message.obtain(null,2/ event /,0/ slot */,0, bundle);msg.replyTo= mMessenger;mService.send(msg);/** Return of the interface set:*/Stringresponce="Registration Done";switch(msg.arg1){case-1:responce ="Not Allowed";break;case-2:responce ="Please connect later";break;}@OverridepublicvoidonServiceConnected(ComponentName name,IBinder service){// Messenger for communicating with serviceMessengermService=newMessenger(service);}};