Message to Activity from AsyncTask
<p>I am trying to send a message to my main activity from an Async task embedded within a Service.  Basically, the Async task has to block on input and it can't run in the main Activity thread (the blocking was removed from the example code below).  When the data comes in though, I need to send it to the main activity.  I am finding that the messages sent below never make it.  If the answer is moving the bind within the Async task, how do you do that?  Pointing to example code would be a big help if possible.</p>

<pre><code>public class InputService2 extends Service {
int bufferSize = 1024;
Process process;
DataInputStream os;
TextView inputView;
byte[] buffer = new byte[bufferSize];
private MyAsyncTask inputTask = null;
       public void onCreate(){
           inputTask = new  MyAsyncTask();
           inputTask.execute((Void[])null);

       }
       private class MyAsyncTask extends AsyncTask&lt;Void,Void,Void&gt; {

        int mValue = 0;
        static final int MSG_SET_VALUE = 3;
            protected void onProgressUpdate(Void progress){

            }

            protected void onPostExecute(Void result) {

            }

            protected Void doInBackground(Void... params) {

                int i = 0;


                try {
                    mValue = 0x23;
            Message message =     Message.obtain(null,MSG_SET_VALUE,mValue,0);
                    mMessenger.send(message);
                }
                catch (Exception e) {

                }


            }
        } 
       class IncomingHandler extends Handler {
            @Override
            public void handleMessage(Message msg) {
            }
        }
        final Messenger mMessenger = new Messenger(new IncomingHandler());
        public IBinder onBind(Intent intent) {
            return mMessenger.getBinder();
        } 

}
</code></pre>

<p><strong>Below is inside the activity:</strong></p>

<pre><code>class IncomingHandler extends Handler {
    @Override
    public void handleMessage(Message msg) {
        Context context = getApplicationContext();
        int duration = Toast.LENGTH_LONG;
        Toast toast = Toast.makeText(context, msg.arg1, duration);
        toast.show();
    }
}

boolean mBound;
private ServiceConnection mConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName className, IBinder service) {
        // This is called when the connection with the service has been
        // established, giving us the object we can use to
        // interact with the service. We are communicating with the
        // service using a Messenger, so here we get a client-side
        // representation of that from the raw IBinder object.
        mService = new Messenger(service);
        mBound = true;
    }

    public void onServiceDisconnected(ComponentName className) {
        // This is called when the connection with the service has been
        // unexpectedly disconnected -- that is, its process crashed.
        mService = null;
        mBound = false;
    }
};

protected void onStart() {
    super.onStart();
    // Bind to the service
    bindService(new Intent(this, InputService2.class), mConnection,
            Context.BIND_AUTO_CREATE);
}
</code></pre>
