簡體   English   中英

由defaultValue引起的將int從活動傳遞到另一個活動的問題

[英]Problem with passing an int from an activity to another caused by the defaultValue

當我嘗試將一個int從一個活動傳遞給另一個活動時,接收者每次都會獲取默認值。

這是我來自發件人活動的代碼

Intent go = new Intent(this,BattleActivity.class);
go.putExtra("Tag", tag);
startActivity(go);

這是接收者活動的代碼

Intent mIntent = getIntent();
int intValue = mIntent.getIntExtra("Tag", 0);

tagView = (TextView) findViewById(R.id.tag);
tagView.setText("The selected number is " + intValue);

也許從:

Intent go = new Intent(this,BattleActivity.class);

相反,請嘗試:

Intent go = new Intent(SenderActivity.this, BattleActivity.class);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM