1

username and password is correct but "if(username=...)" this block not work. There is no error too. Its return 0 value to onPostExecute() method.

@Override
public Integer doInBackground(Void... Params){
    try{
           ....
            if(userName=="sinan" && password=="123456")
            {
                returnValue=1;
                break;
            }
            else
            {
                returnValue=0;
            }
        }
        return returnValue;
    }
    catch (Exception ex)
    {
        return (-1);
    }
}

asdasd

   @Override
    protected void onPostExecute(Integer result){ 
  super.onPostExecute(result);      
  if(result==1)
    {
        txtViewUserName.setText(userName);
        txtViewPassword.setText(password);
    }
    else if(result.intValue()==0)
    {
        txtViewUserName.setText("Result 0");
    }
    ....
}
Sinan Barut
  • 510
  • 1
  • 6
  • 14

2 Answers2

4

Your Mistake Was You Were Using == operator,The == operator compares the objects location in memory

Use equals() method in place of == operator it compares the Two String Objects

   Override
     public Integer doInBackground(Void... Params){
         try{
       ....
        if(userName.equals("sinan") && password.equals("123456"))
        {
            returnValue=1;
            break;
        }
        else
        {
            returnValue=0;
        }
    }
    return returnValue;
}
catch (Exception ex)
{
    return (-1);
}

}

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
Deepanshu Gandhi
  • 490
  • 3
  • 10
1

for String comparison you have to use equals() method:

 if(userName.equals("sinan") && password.equals("123456"))

don´t worry, very common mistake when we to start in java programming :)

Remember:

.equals() This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

== : tests for reference equality.

.equals() : tests for value equality.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268