Android asynchronous dialogs causing problems?
<p>I'm quite aware that Android manages its Dialogs in an asynchronous way for improving performance,memory improvement,etc. But the problem is that I have encountered a simple situation where I need to fetch an input given by the user in order to follow with the execution of the app.Since I am using a Dialog this all messes up cause the flow of the app continues wether or not the user has written something in my prompt dialog. Is there any way of solving this????</p>

<p>Here is the code:</p>

<pre><code>@Override 
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId())
    {
    case 1:
        startActivity(new Intent("HOMESCREEN"));
        break;
    case 2:
        String searched = prompt("Search", HomeScreen.this);
        Intent data = new Intent("RESULTSSCREEN");
        data.putExtra("SearchCriteria", "");
        startActivity(data);
        break;
    case 3:
        //....
        break;
    }

    return true;
}
</code></pre>

<p>Here is the code for prompt:</p>

<pre><code>public String prompt(String message, Context ctx)
    {
        //load some kind of a view
        LayoutInflater li = LayoutInflater.from(ctx);
        View view = li.inflate(R.layout.prompt_layout, null);
        //get a builder and set the view
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        builder.setTitle("Search");
        builder.setView(view);
        //add buttons and listener
        PromptListener pl = new PromptListener(view);
        builder.setPositiveButton("OK", pl);
        builder.setNegativeButton("Cancel", pl);
        //get the dialog
        AlertDialog ad = builder.create();
        //show
        ad.show();

        return pl.getPromptReply();
    }
</code></pre>

<p>The problem is that the intent data is executing before the user finishes up writing the search criteria.
Regards</p>
