Code example for Messenger

Methods: send

0
            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);
	    } 
	     
	    public void onServiceDisconnected(ComponentName className) {
	        //error during connection / something went wrong during binding. 
            //notify lock, since we have not set response to something, the main thread 
            //will recognize that something has gone wrong 
            this.sb.get().lock.notifyAll();
	    } 
 
        @Override 
        public void handleMessage(Message msg){
            this.sb.get().response = Message.obtain(msg);
             
            synchronized(this.sb.get().lock){
                try { 
                    this.sb.get().lock.notifyAll();
                } 
                catch(IllegalMonitorStateException e){}
            } 
        } 
 
        public void sendToService(Message msg){
            msg.replyTo = responseMessenger;
            try { 
                serviceMessenger.send(msg);
            } 
            catch(Exception e){}
        } 
     
    }