[英]Problem with passing an int from an activity to another caused by the defaultValue
When I try to pass an int from an activity to another the receiver gets the default value every time. 当我尝试将一个int从一个活动传递给另一个活动时,接收者每次都会获取默认值。
This is my code from the sender activity 这是我来自发件人活动的代码
Intent go = new Intent(this,BattleActivity.class);
go.putExtra("Tag", tag);
startActivity(go);
and this is the code from the receiver activity 这是接收者活动的代码
Intent mIntent = getIntent();
int intValue = mIntent.getIntExtra("Tag", 0);
tagView = (TextView) findViewById(R.id.tag);
tagView.setText("The selected number is " + intValue);
Probably this from : 也许这从:
Intent go = new Intent(this,BattleActivity.class);
Instead, try: 相反,请尝试:
Intent go = new Intent(SenderActivity.this, BattleActivity.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.