I am calling the 2nd Activity from 1st:
Intent intent = new Intent();
intent.setClass(MainActivity.this, SecondActivity.class);
Bundle b = new Bundle();
b.putInt(SecondActivity.ID,id);
System.out.println("id*"+id);
b.putString(SecondActivity.NAME, name);
System.out.println("name*"+name);
intent.putExtras(b);
startActivity(intent);
LogCat:
11-06 19:33:57.451: I/System.out(7987): id*2
11-06 19:33:57.451: I/System.out(7987): name*MrBlack
2nd Activity:
public static final String ID = "";
public static final String NAME = "";
................
Bundle extras = getIntent().getExtras();
int id = extras.getInt(ID);
System.out.println("extras.getInt(ID)*"+extras.getInt(ID));
System.out.println("extras.getString(ID)*"+extras.getString(ID));
System.out.println("extras.getString(NAME)*"+extras.getString(NAME));
TextView tvFirmaName = (TextView) findViewById(R.id.tvName);
tvFirmaName.setText(extras.getString(NAME));
LogCat:
11-06 19:33:57.721: I/System.out(7987): extras.getInt(ID)*0
11-06 19:33:57.731: I/System.out(7987): extras.getString(ID)*MrBlack
11-06 19:33:57.731: I/System.out(7987): extras.getString(NAME)*MrBlack
I do not understand why int value 2 is passing as 0
And why extras.getString(ID) is “MrBlack” value!?
Please, let me know where I was wrong..
You need to provide values for those strings, they act as variable names for the info you’re passing. Their values are arbitrary, so long as they’re not equal to one another.
Cheers