Code example for Messenger

0
        mConnection = new AsyncChannelConnection();
 
        /* Initialize the source information */ 
        mSrcContext = srcContext;
        mSrcHandler = srcHandler;
        mSrcMessenger = new Messenger(srcHandler);
 
        /* 
         * Initialize destination information to null they will 
         * be initialized when the AsyncChannelConnection#onServiceConnected 
         * is called 
         */ 
        mDstMessenger = null;
 
        /* Send intent to create the connection */ 
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClassName(dstPackageName, dstClassName);
        boolean result = srcContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
        if (DBG) log("connect srcHandler to dst Package & class X result=" + result);
        return result ? STATUS_SUCCESSFUL : STATUS_BINDING_UNSUCCESSFUL;
    }