android 中的activity:
private void switchActivity(String key)
{
String r="123";
Bundle basket=new Bundle();
//basket.putString("key", key);
basket.putString("roll", r);
Intent i=new Intent(Andprj.this, extra.class);
i.putExtras(basket);
startActivity(i);
}
在其他activity:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.exam);
tv=(TextView) findViewById(R.id.t1);
setContentView(R.layout.exam);
Bundle gotbasket=getIntent().getExtras();
String gotbread=gotbasket.getString("roll");
tv.setText(gotbread);
}
顯示出來的只有默認值的textview。
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.exam);
tv=(TextView) findViewById(R.id.t1);
Bundle gotbasket=getIntent().getExtras();
String gotbread=gotbasket.getString("roll");
tv.setText(gotbread);
}
試試這個方法吧