0

I am using the bluetooth chat example and i have the following problem..

When i add an if statement inside handler it always return false..

  case MESSAGE_READ:
                    byte[] readBuf = (byte[]) msg.obj;
                    String stringMsg = new String(readBuf);

                    if ( stringMsg == "a"){
                        Log.i(tag,"x RECEIVED OK...");
                    }
                    break;

When i debug the program i get:

stringMsg = {java.lang.String@830020784928}"a��������....."
        value = {char[1364]830020788104}
               [0] = 'a' 97
               [1] = '\u0000' 0
               [2] = '\u0000' 0
               [3] = '\u0000' 0
               [4] = '\u0000' 0
               [5] = '\u0000' 0
               [6] = '\u0000' 0 
                  ...
                  ...
                  ...
                  ...
                  ...
        hashCode = 0
          offset = 0
           count = 1024

Can you please help me to read the inputstream save the Character as a string(stringMsg) and be able to use an if statement to check its content ?

Thank you in advance..!

Larry
  • 3
  • 2

1 Answers1

0

if (stringMsg == "a") should be if(stringMsg.equals("a")) if you want to compare the value and not the reference.

David C Adams
  • 1,953
  • 12
  • 12