title: Android: wait on user input from dialog?
body: <p>I would like to implement a method that displays a dialog, waits until the dialog is dismissed, and then returns a result depending on the dialog contents.  Is this possible?</p>
  
  <pre><code>public String getUserInput()
  {
      //do something to show dialog
      String input = //get input from dialog
      return input;
  }
  </code></pre>
  
  <p>I am actually trying to implement an interface which has method "public String getUserInput()", where the returned String must be retrieved via dialog.  This is easily done in java, seems impossible in android?</p>
  
  <p>EDIT: Posting some sample code as requested in comment</p>
  
  <p><code>getInput()</code> must be called from a background thread (I call it from an AsynchTask).  getInput() displays a dialog and calls wait.  When the ok button is pressed on the dialog, the dialog sets the user input in a member variable and calls notify.  When notify is called, getInput() continues and returns the member variable.</p>
  
  <pre><code>String m_Input;
  
  public synchronized String getInput()
  {
      runOnUiThread(new Runnable() 
      {
          @Override
          public void run() 
          {
              AlertDialog.Builder alert = new AlertDialog.Builder(context);
              //customize alert dialog to allow desired input
              alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton)
              {
                            m_Input = alert.getCustomInput();
                            notify();
              }
          });
          alert.show();   
          }
      });
  
      try 
      {
           wait();
      } 
      catch (InterruptedException e) 
      {
      }
  
      return m_Input;
  }
  </code></pre>