[英]Passing an int value from an Activity Fragment to another Fragment
[英]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.