我想将整数值从一个 Activity 传递到另一个 Activity ,我尝试这样做,但值未传递,请告诉我正确的解决方案。
这是我想要将值传递给其他 Activity 的 Activity 代码。
Intent intent = new Intent(getApplicationContext(),
TotalCalories.class);
intent.putExtra("Total Sum", sum);
startActivity(intent);
这是我想要获取值的代码。
Bundle extras = getIntent().getExtras();
int sum = Integer.parseInt(extras.getString("Total Sum"));
TextView textview = (TextView) findViewById(R.id.textViewname);
textview.setText(extras.getString("Total Sum"));
最佳答案
尝试像这样更改 get String 中的 Totalsum
Intent intent = new Intent(getApplicationContext(),
TotalCalories.class);
intent.putExtra("TotalSum", sum);
startActivity(intent);
将其添加到新 Activity 的 Oncreate 中
Bundle extras = getIntent().getExtras();
int sum = Integer.parseInt(extras.getString("TotalSum"));
TextView textview = (TextView) findViewById(R.id.textViewname);
textview.setText("Your OutPut"+sum);
关于android 整数值从一个 Activity 传递到另一个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31086529/