UPDATE 1
========

I did some more debugging and found that the constructor is run from the main UI thread but the handleMessage(Message) method is run on the Thread I created, which completely contradicts my understanding of Handlers.

Problem
=======

I've been working on Android for a while now and I've run into an issue that doesn't seem to be documented. I'm not doing anything special with my code. I can't seem to get my application to create any UI elements such as Alert Dialogs and Toast messages from a Handler's handleMessage method.

Additionally, I get a "Thread has not called Looper.prepare()" exception. However, I believe that I shouldn't even need to call Looper.prepare() since I'm not creating a Handler inside of the Thread object. I'm calling the constructor in the main UI thread and then passing it to the new Thread's constructor.

What I Expect
-------------

I should see a Toast message as well as an Alert Dialog.

What Actually Happens
---------------------

Nothing. I've run the debugger on the application and I find that the JVM does launch the Thread. The run method is called and the message is dispatched. The handler handles the method and I run through all the methods of creating the AlertDialog as well as the Toast message but nothing ever shows up.

I've run this application on my Emulator running 4.2, my friend's Samsung Galaxy S3 running 4.0.4, and my own Droid X2 running 2.3.5.

Flow of the Program
===================

1. I create a Handler on the UI thread.
2. I create and start a Thread that will dispatch a message to the Handler.
3. The handler will handle the message

Source Code
===========

<http://pastebin.com/cRfaW7b0>

```
package com.nguyenmp.ErrorTest;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MyActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //Init the UI
        setContentView(R.layout.main);

        //Create a new handler, passing it the current activity context
        final Handler handler = new MyHandler(MyActivity.this);

        //Bind a listener to the button on the UI
        View view = findViewById(R.id.button);
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //Start a new thread that will send a message to that handler
                new MyThread(handler).start();
            }

        });
    }

    private class MyThread extends Thread {
        private final Handler mHandler;

        MyThread(Handler handler) {
            mHandler = handler;
        }

        @Override
        public void run() {
            //Dispatch message to UI thread asynchronously
            Looper.prepare();
            mHandler.dispatchMessage(mHandler.obtainMessage());
        }
    }

    private class MyHandler extends Handler {
        private final Context mContext;

        MyHandler(Context context) {
            mContext = context;
        }

        @Override
        public void handleMessage(Message msg) {
            //Show that we got the message
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle("HelloWorld");
            builder.setMessage("It worked!");
            builder.show();

            //Another variant of showing that we got the message
            Toast.makeText(mContext, "Message Received", Toast.LENGTH_SHORT).show();

            System.out.println("Yeah");
        }
    }
}

```
['https://Stackoverflow.com/questions/14950314', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/783338/']
You should use <http://developer.android.com/reference/android/os/Handler.html#sendMessage(android.os.Message)>
to send the message that will be later processed by handleMessage.
The problem was that I was calling dispatchMessage(Message) which is executed imediately on the current thread. I should have been using sendMessage(Message) which would enqueue the given Message to the original thread's message queue that created the Handler in the first place.