My if statement doesn't work

I am writing a utility application in Android

. In this application, I receive commands from the main activity using an event onStartCommand

. The block IF

checks the variable. As you can see in the picture (debug mode) the value is "start", but the operator IF

doesn't work and is redirected to Else

. why?

enter image description here

+1


source to share


2 answers


try with .equals

will help you ...

String is not Primary Data type in java

Always use .equals() when you have Object

andString is Object



==

is only for primitive data type

and ==

in an object to compare your values ​​String Refrences ... not value ...

if(ReceivedCommandFromUser.equals("start"))
    {

      }

      

+5


source


When working with strings in Java, use the .equals () method.

For example...



if(RecievedCommandFromUser.equals("start"){}

      

Must work.

+2


source







All Articles