我从第 1 次调用第 2 次活动:
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);
日志猫:
11-06 19:33:57.451: I/System.out(7987): id*2
11-06 19:33:57.451: I/System.out(7987): name*MrBlack
第二个活动:
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));
日志猫:
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
我不明白为什么 int 值 2 作为 0 传递而为什么 extras.getString(ID) 是“MrBlack”值!?
请让我知道我错在哪里..