I am working on an android app. I have a string in one of my first activity. And I use intent.putExtra()
to pass that string to second activity which I started in first activity. Here are the related parts of activity codes:
First Activity
final ListView lv = (ListView) findViewById(R.id.listView1);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
String selectedFromList = (lv.getItemAtPosition(arg2).toString());
Intent content_umre_Intent = new Intent("com.uygulama.hacc.ContentActivity");
content_umre_Intent.putExtra("key", selectedFromList);
startActivity(content_umre_Intent);
}
});
Second Activity
Context context = getApplicationContext();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
String text = getIntent().getStringExtra("key").toString();
if(text=="abc"){
toast.show();
}
There is something curios here. I put toast.show()
outside of if statement, and I saw that it is equal to "abc".
However even the variable text
is exactly equal to "abc" it doesnt go enter the if statement.
Do you have an idea why this happens? I couldnt find any reason. I really need help right now.
Any help would be appreciated.