title: onPostExecute runs before doInBackground method is finished
body: <p>So,I simply made a login screen where the data comes from an external server.
  All of that happens in the background method.it all works correctly except for onPost and onPre methods.
  I don't think they are doing their job.</p>
  
  <p>while the onBackground method is running i would like to:</p>
  
  <p>1.Show a message if the data is right or wrong.</p>
  
  <p>2.Show a custom progress dialog i made while doinbackground is running.</p>
  
  <p>But neither of them work,any ideas?</p>
  
  <p>Here is my code!</p>
  
  <pre><code> public class DoLogin extends AsyncTask&lt;String,String,String&gt;
      {
          String message = "";
          Boolean isSuccess = false;
  
          String userid = dename.getText().toString();
          String password = pass.getText().toString();
  
  
  
          @Override
          protected void onPreExecute() {
             progressDialog.showProgress(SignInAr.this,"Loading...",false);
          }
  
  
  
          @Override
          protected String doInBackground(String... params) {
              new Thread(new Runnable() {
                  @Override
                  public void run() {
                      if(userid.trim().equals("")|| password.trim().equals(""))
                          message = "Please enter Username and Password";
                      else
                      {
                          try {
                              Connection con = connectionClass.CONN();
                              if (con == null) {
                                  message = "Error in connection with SQL server please contact the administrator";
                                  isSuccess = false;
                              } else {
                                  String query = "SELECT * FROM CustomerData where CustomerMobile='" + userid + "' and CustomerPassword='" + password + "'";
                                  Statement stmt = con.createStatement();
                                  ResultSet rs = stmt.executeQuery(query);
  
  
  
  
                                  if(rs.next())
                                  {
                                      String id = rs.getString("CustomerID");
                                      String mob = rs.getString("CustomerMobile");
                                      String lng = getIntent().getStringExtra("lng");
                                      String lat = getIntent().getStringExtra("lat");
                                      message = "Welcome " + userid;
                                      Intent intent = new Intent(SignInAr.this,agzakhana_mainAr.class);
                                      intent.putExtra("lat",lat);
                                      intent.putExtra("lng",lng);
                                      intent.putExtra("nameid",id);
                                      String getname = rs.getString("CustomerName");
                                      intent.putExtra("nameofcus",getname);
                                      intent.putExtra("mob",mob);
                                      startActivity(intent);
                                      finish();
                                      isSuccess=true;
  
  
  
                                  }
                                  else
                                  {
                                      message = "Wrong info";
                                      isSuccess = false;
                                  }
                              }
                          }
                          catch (Exception ex)
                          {
                              isSuccess = false;
                              message = "Exceptions"+ex;
                          }
                      }
                  }
              }).start();
  
              return message;
          }
  
  
  
          @Override
          protected void onPostExecute(String r) {
  
             progressDialog.hideProgress();
              System.out.println("Message is: "+ r + "and isSuccess = "+ isSuccess);
  
              if(!isSuccess) {
                  Toast.makeText(SignInAr.this,r,Toast.LENGTH_LONG).show();
              }
  
          }
      }
  </code></pre>
  
  <p>Here is how i call the asynctask:</p>
  
  <pre><code> submit.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  DoLogin doLogin = new DoLogin();
                  doLogin.execute();
  
              }
          });
  </code></pre>