好吧,我不明白为什么字符串比较不起作用
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();
}
好吧,所有三个 if 条件都没有给出任何错误,即使 returnState = user 或 returnState = no_user,第二个活动也永远不会开始。如果returnState = user,我想开始另一个活动,但无论如何,如果阻塞它就不会进入