0

I am creating a Handler but for some reason the if statement does not trigger. The Log is printing out the correct value right before the if statement.

mHandler = new Handler() { 
@Override public void handleMessage(Message msg) { 
    String s=(String)msg.obj;
    s = s.trim();
    Log.v("mHandler reply", s);
    if(s == "OK"){
       Dialog.dismiss();
    }
}

};

Here is the log

03-24 09:02:53.707: V/mHandler reply(7331): OK

Why is this not working?

AssemblyX
  • 1,841
  • 1
  • 13
  • 15
  • Use `equals()` for testing string equality.http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – laalto Mar 24 '14 at 15:17

1 Answers1

2

Use equals() method instead of == operator for String comparison as follows...

if(s.equals("OK")){
   Dialog.dismiss();
}

To get more information check How do I compare strings in Java?

Community
  • 1
  • 1
Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41