Dilazak
Dilazak

Reputation: 149

Why are the Alert dialogs not shown in proper order?

I have a question regarding the display of alert dialogs in a sequence one after the other. I am trying to display three alert dialogs but every time the third one is the fist one to appear the second one should be second in this case and the first one is always the last. I want them to be displayed as written in the code order. Please consider the code and suggest me why is this happening and a solid solution.

private static class MyHandler extends Handler {

    MainActivity activity;

    public MyHandler(MainActivity activity){
        this.activity = activity;
    }
    @Override
    public void handleMessage(Message msg) 
    {
        if(activity.connectionToTupleSpace == true)
        {
            activity.showDialog("Dialog 1", "It should be displayed first");
            activity.showDialog("Dialog 2", "It should be displayed second");
            activity.showDialog("Dialog 3", "It should be displayed third");
        }
        else
        {
            Toast.makeText(activity.getBaseContext(), " No connection to Tuple Space Server", Toast.LENGTH_SHORT).show();

        }
    }
};//handler for Thread



private void showDialog(String title, String message)
{
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setTitle(title);
    builder.setMessage(message);
    builder.setPositiveButton("OK", null);
    builder.show();
}

Upvotes: 2

Views: 169

Answers (2)

NguyenVanTuMTA
NguyenVanTuMTA

Reputation: 21

As I know, in your code, you using 3 instances of MainActivity, so there are 3 activites, so if you know "stack", you see that it is reasonable. I think you should add value to set priority for each AlertDialog.

Upvotes: 0

Shpongoloid
Shpongoloid

Reputation: 106

They are showing in the right order.

First you show dialog number 1. Then you show dialog number 2 ON TOP of number 1. Then you show dialog number 3 ON TOP of number 2.

This means that number 3 will be shown first because that is the latest one you added.

So the easiest solution is: just reverse the order, first show 3, then 2 and then 1 :)

Upvotes: 1

Related Questions