第一个 activity 中的代码,用来传递第一个和第二个值:
Intent i = new Intent(this, OtherScreen.class);
i.putExtra("id1", "first");
i.putExtra("id2", "second");
startActivity(i);
在其它的类中是这样的:
Intent i = getIntent();
Bundle extras = i.getExtras();
String result = extras.getString("id1");
System.out.println("yeah"+result);
但是当我运行它的时候,返回 null,这是什么问题?如果我用这种方式创建 getString,有语法错误。
String result = extras.getString(id1);
String result = extras.getString("id1","default value");