我有三个活动导致相同的活动,其中显示数字并根据它的来源进行一些计算,当我在每个意图中只有一个额外时,一切都很顺利,但是让我说我需要的活动一个知道选择了什么选项,所以我又添加了三个额外的选项。
但是我在活动1中添加的这三个额外内容似乎在最后一个活动中没有被识别出来。
活动一
if (selectedItem.trim().equals("100mm")) {
Total1 = (int) (a * b * 10);
}
else if (selectedItem.trim().equals("215mm")) {
Total2 = (int) (a * b * 20);
}
else if (selectedItem.trim().equals("325")) {
Total3 = (int) (a * b * 30);
}
else if (selectedItem.trim().equals("hollow ")) {
Total4 = (int) (a * b * 10);
}
Intent intent = new Intent(CalculateB.this,
WlAmounts.class);
intent.putExtra("Result100",Total1);
intent.putExtra("Result215", Total2);
intent.putExtra("Result325", Total3);
intent.putExtra("ResultHollow",Total4);
startActivity(intent);
上次活动
Intent sender = getIntent();
int edge = sender.getExtras().getInt("Result100");
int flat = sender.getExtras().getInt("Result215");
int wide = sender.getExtras().getInt("Result325");
int hollow = sender.getExtras().getInt("ResultHollow");
int opes1 = sender.getExtras().getInt("ResultOpe1");
int opes2 = sender.getExtras().getInt("ResultOpe2");
if (getIntent().hasExtra("Result100")) {
answer.setText(edge + "");
} else if (getIntent().hasExtra("Result215")) {
answer.setText(flat + "");
//i'm doing some calculations here
} else if (getIntent().hasExtra("Result325")) {
answer.setText(wide + "");
//i'm doing some calculations here
} else if (getIntent().hasExtra("ResultHollow")) {
answer.setText(hollow + "");
//i'm doing some calculations here
} else if (getIntent().hasExtra("ResultOpe1")) {
answer.setText(opes1 + "");
//i'm doing some calculations here
} else if (getIntent().hasExtra("ResultOpe2")) {
answer.setText(opes2 + "");
答案 0 :(得分:1)
只需保留一个额外的意图,这将有助于确定呼叫来自哪个活动。然后提取其他各自的意图