I would like to start an activity only if the string I pass with putExtra from another activity equals 'search' like so:
action = intent.getStringExtra("cause");
Button btnBack = findViewById(R.id.btnBack);
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(action == "search") {
Intent intent2 = new Intent(profiloutente.this, ricerca.class);
startActivity(intent2);
}
}
});
But, the condition always seems to be false (so the activity doesn't start) even if the variable containing the get Extra equals "search". I don't understand why this happens. Could someone help me?