0
public class BabyName extends Activity implements View.OnClickListener, Runnable{
    /** Called when the activity is first created. */

    Login loginclass=new Login();
    ProgressDialog dialog;

    Thread t=new Thread(this, "sample");

     AlertDialog al;
     long id;
     boolean flg=false;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
        Button launch=(Button)findViewById(R.id.login_button);
        launch.setOnClickListener(this);
    }

    public void onClick(View viewparam){
        EditText username=(EditText)findViewById(R.id.txt_username);
        EditText password=(EditText)findViewById(R.id.txt_password);

        String sUserName = username.getText().toString();
        String sPassword = password.getText().toString();


            dialog=ProgressDialog.show(BabyName.this, "", "Please wait for few seconds...", true);

            loginclass.setId(sUserName);
            loginclass.setPassword(sPassword);     
            al=new AlertDialog.Builder(this).create();
            id=t.getId();                
            t.start();          
            message();


    }
    public void run(){    
            Get_Data getdata=new Get_Data();        
            getdata.logincheck(loginclass);
            dialog.dismiss();       
    }

    public void message(){

        if(loginclass.getStatus().trim().equals("true")){           
            dialog.dismiss();
            /*  Intent i = new Intent(BabyNames.this, ChoiceActivity.class);
                startActivityForResult(i, SUB_ACTIVITY_REQUEST_CODE);*/
            }else if(loginclass.getStatus().trim().equals("false")){

                al.setTitle("Error");
                al.setMessage("Username or password incorrect!!");
                al.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      return;
                  } }); 
                al.show();
            }else {

                //al=new AlertDialog.Builder(this).create();
                al.setTitle("Http Error");
                al.setMessage("Not Connected");
                al.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      return;
                  } }); 
                al.show();
            }
    }
}

This is the code of login page of android and when i enter click login button the progressdialog appears and after that alertbox must be shown if username or password incorrect but it is not showing that alert.

so is there any problem in threading or something else? please help me

Jugal Inani
  • 133
  • 1
  • 17

1 Answers1

1

You can't show a second dialog on top of another dialog.

You can only show one dialog at a time on top of an activity.

What you can do, is set the error message on the login view, then dismiss the progress dialog, and when that is dismissed the user will see something went wrong.

Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • I want to show alert dialog after a progressdialog get dismiss. Is it possible? – Jugal Inani Jun 26 '10 at 10:36
  • I think you didn't got my question properly what i want is when the user clicks on login button the progressdialog appears untill we get the server data and as soon as i get it i want to dismiss a progress dialog and show a alert dialog if login data is incorrect.. – Jugal Inani Jun 26 '10 at 10:42
  • Yeah, that can be done. Use AsyncTask to get the response back from the server, and when the Task/Thread completes dismiss the dialog, and show the new one. As I see in your code, you don't wait till the end of the Thread. When you call t.start() that will start, but calling immediate message() is bad, as the thread is not finished, just started. Look into AsyncTask, there are plenty of answer for that too here on this site. – Pentium10 Jun 26 '10 at 11:34