Android 如何知道哪个意图打开了活动

Android 如何知道哪个意图打开了活动,android,Android,嗨,我有两个活动,一个活动。打开“活动”时,将显示两个“活动”中任何一个的编号 我需要知道数字的来源,这样我才能进行适当的计算,我想我需要一个if语句,但不知道如何开始 Intent intent = new Intent(calculateA.this, WAmounts.class); intent.putExtra("Result",Total); startActivity(intent); Intent intent = new Intent(CalcB.t

嗨,我有两个活动,一个活动。打开“活动”时,将显示两个“活动”中任何一个的编号

我需要知道数字的来源,这样我才能进行适当的计算,我想我需要一个if语句,但不知道如何开始

Intent intent = new Intent(calculateA.this,
    WAmounts.class);
    intent.putExtra("Result",Total);
    startActivity(intent);


Intent intent = new Intent(CalcB.this,
    WAmounts.class);
    intent.putExtra("ResultB",Total);
        startActivity(intent);
第三种活动

 Intent sender = getIntent();
    int result = sender.getExtras().getInt("Result");
    answer.setText(result+"");


    int resultB = sender.getExtras().getInt("ResultB");
    answer.setText(resultB+"");

//If number came from first activity  

    a = Integer.parseInt (answer.getText().toString());
    total = (float) (a *x); 
    sd.setText(String.format("%.1f" ,total));



    b = Float.parseFloat (sand.getText().toString());
    total1 = (int)Math.ceil (b*f);
    c.setText(Integer.toString(total1));

  //If number came from second activity     

  a = Integer.parseInt (answer.getText().toString());
  total = (float) (a *x); 
  sd.setText(String.format("%.1f" ,total));



  b = Float.parseFloat (sand.getText().toString());
  total1 = (int)Math.ceil (b*f);
  c.setText(Integer.toString(total1));

因为您将额外的调用为“result”和“resultB”,所以可以使用sender.hasExtra(“result”),如果它返回false,您就知道是哪个活动启动了此意图


请注意,代码中的bot sender和sender1具有相同的意图,即启动此活动的意图。您不必两次获取它。

因为您将额外的调用为“result”和“resultB”,所以可以使用sender.hasExtra(“result”),如果它返回false,您就知道是哪个活动启动了此目的

请注意,代码中的bot sender和sender1具有相同的意图,即启动此活动的意图。您不必两次获得它。

只需传递一些“额外信息”,如下所示:

然后在新的活动中使用

if (extras != null) {
    String value = extras.getString("yourLabel");
}
只需传递一些“额外信息”,如下所示:

然后在新的活动中使用

if (extras != null) {
    String value = extras.getString("yourLabel");
}

“我有两个活动去一个活动”-你是什么意思?“我有两个活动去一个活动”-你是什么意思?这就是我做的。我创建了一个
“key”
来发送一个名为“source”的消息,并分配了一个我可以很容易记住的标记,然后在接收
活动中得到我的
意图时检查
“source”
是什么。我创建了一个
“key”
来发送被调用的“source”`并分配了一个我可以很容易记住的标签,然后在接收
活动中得到我的
意图时检查
“source”
是什么