Q:

Launch AlertDialog from Handler

in my activity I originally used a handler to update the UI with data received from the internet. I now want to display this data inside an alertdialog instead of on the UI screen. The program works by pressing a button, gets the information and displays it on the screen. this is done by calling the necessary message for the handler. I managed to do for a Toast message and I thought the alertdialog would follow the same logic but I get the error:
RunTime Error: Unable to add Window -- token null is not for an application

Here is my code for the handler message, where the error is apparently caused (Line 84 which is the .show() method line):
Handler handler = new Handler()
{
    @Override
    public void handleMessage(Message msg) 
    {
        Context context = getApplicationContext();

        switch( msg.what )
        {
            case DISPLAY_TOAST:
                Toast t = Toast.makeText( context,"Toast Test",Toast.LENGTH_SHORT );
                t.show();       
            break;

            case UPDATE_UI: 
                htmlData.setText( feedback );           
            break;

            case DISPLAY_ALERT_DIALOG:

                passTime = new AlertDialog.Builder( context );
                passTime.setTitle( alertDialogTitleStrg );
                passTime.setMessage( alertDialogMsgStrg );
                passTime.show();

            break;
        }

    }
}; 

A:

Your context object is wrong, the simplest way you can do is the following:
passTime = new AlertDialog.Builder( YourActivity.this );

greetings

