1

In my

onCreate

I am setting

myString = getIntent().getStringExtra("sentString");

and after that

if (myString == "test") {...}

fails to execute...

even though afterwards

btnTest.setText(myString);

Works

What is the problem?

Daniel
  • 1,064
  • 2
  • 13
  • 30

1 Answers1

8

Always use String.equals() when comparing strings. The == will just compare the reference.

Example: instead of

if (myString == "test") {...}

use:

if (myString.equals("test")) {...}
John Leehey
  • 22,052
  • 8
  • 61
  • 88