I am trying to open a AlertDialog. When this AlertDialog is opened, the threads need to wait for user input in order to continue its program. I read that I need to lock the object thats need to wait and notified. When I run this code on my phone. The alertdialog won't show, and it looks like the app is looping, because after a few seconds I get a message that the app isn't responding. Below you will find the code I wrote.. By the way. I am a virgin to android programming. So please be gentle :P
public class EditTagActivity extends Activity{  
AlertDialog alertDialog;
Runnable h = new Runnable()
{
    @ Override
    public void run() 
    {
        alertDialog.show();
        synchronized(g)
        {
            try 
            {
                Log.d("Threads", "g.wait()");
                g.wait();
            } 
            catch (InterruptedException e) 
            {
                e.printStackTrace();
            }
        }           
    }
};
Runnable g = new Runnable() 
{
    @Override
    public void run() 
    {
        Log.d("Threads", "createAlertDialog()");
        createAlertDialog();
        runOnUiThread(h);
    }
};
public AlertDialog alert;
Runnable test = new dialogManager();
@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_tag);
    Log.d("Threads", "setup()");
    setup();
}
void setup() 
{
    Log.d("Threads", "g.run()");
    g.run();
}
void createAlertDialog() 
{
    Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Alert");
    alert.setMessage("Flaq");
    alert.setPositiveButton("OK", new DialogInterface.OnClickListener() 
    {
        public void onClick(DialogInterface dialog, int which) 
        {
            synchronized(g)
            {
                Log.d("Threads", "g.notifyAll");    
                g.notifyAll();
            }
        }
    });
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() 
    {
        public void onClick(DialogInterface dialog, int which) 
        {
            synchronized(g)
            {
                Log.d("Threads", "g.notifyAll");
                g.notifyAll();
            }
        }
    });
    alertDialog = alert.create();
}
}
 
     
     
    