I want to compare a string literal that is “failed” to a string that has been passed to this function, but my problem is that the string that is passed “result” is not the same as the string fail, and i explicitly passed “failed” to the function.
if(result.equals(fail))
always returns false for me
protected void onPostExecute(String result) {
super.onPostExecute(result);
TextView data_details = (TextView)findViewById(R.id.results_tab);
data_details.setText(result); // THIS PRINTS OUT THE VALUE TO SCREEN WHICH IS 'failed'
String fail = "failed";
if(result.equals(fail))
{
Intent redirect = new Intent(LogActivity.this, MainActivity.class);
redirect.putExtra("error", result);
startActivity(redirect);
finish();
}
}
And also I tried:
if(result.equalsIgnoreCase("failed"))
Your String variables might contain white spaces, i suggest you to check if condition as follows,