Well I can not understand why string comparison not working
protected String doInBackground(String... args)
{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url_login);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity entity = httpResponse.getEntity();
InputStream is = entity.getContent();
String returnState = new String();
returnState = convertStreamToString(is);
Log.d("retunState ", returnState); // returning desired string
//if (returnState=="user") // this is not working, however returnState = user
// OR
//if (returnState.equals("user"))
// OR
if (returnState.equalsIgnoreCase("user")) // this is not working also
{
Intent i = new Intent(Main.this, SecondPage.class);
startActivity(i);
finish();
}
} // close of doInbackgorund function
private static String convertStreamToString(InputStream is)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append((line + "\n"));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
Well the all the three if-conditions do not give any error and the second activity never start even if returnState = user or returnState= no_user. I want to start another activity if returnState = user but in any case, it just does not go in if block
Your first
ifstatement is skipping your next statement as it is false. Comment out the first if.Its possible you also have whitespace in your returnState. Try using
.trim()