Code example for Messenger

0
    } 
 
    private class HgServiceConnection extends Handler implements ServiceConnection {
 
        Messenger serviceMessenger = null;
        Messenger responseMessenger = new Messenger(this);
 
        private WeakReference<ServiceBinder> sb;
     
        public HgServiceConnection(Looper looper, ServiceBinder sb){
            super(looper);
             
            this.sb = new WeakReference<ServiceBinder>(sb);
        } 
 
        public void onServiceConnected(ComponentName className, IBinder service) {
	        //service has been connected to this, send the given message 
	        serviceMessenger = new Messenger(service);
	        sendToService(this.sb.get().in);
	    }