我无法在两个活动之间传递int变量,它总是传递0 ...这是我的代码,请帮助....
发件人类:
Intent myIntent = new Intent(Senderclass.this, Receiverclass.class);
int b = 2;
int bb = 2;
myIntent.putExtra("aaa", b);
myIntent.putExtra("bbb", bb);
startActivity(myIntent);
Reciver Class:
Bundle bundle=getIntent().getExtras();
的onCreate ....
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub super.onCreate(savedInstanceState);
setContentView(R.layout.on_a_same_device3);
Bundle bundle=getIntent().getExtras();
if(bundle != null) {
aaa = getIntent().getIntExtra("aaa", 9);
bbb = getIntent().getIntExtra("bbb", 9);
}
}
答案 0 :(得分:0)
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub super.onCreate(savedInstanceState);
setContentView(R.layout.on_a_same_device3);
Bundle bundle=getIntent().getExtras();
if(bundle != null) {
aaa = bundle.getInt("aaa");//I am not using default value.
bbb = bundle.getInt("bbb", 9);//Using default value.
}
}