7

我想将调用活动与其他活动进行比较,以了解哪个调用了当前活动。我试过了:

getCallingActivity().getClassName().toString().equals(MainActivity.class.toString())

它不起作用,除了在调用 Intent 中传递一个值,我们如何使用getCallingActivity()or比较类getCallingPackage()

4

1 回答 1

9

如果该活动是为另一个活动的结果而启动的,您可以通过以下方式比较调用活动。

  if (getCallingActivity().getClassName().equals(MainActivity.class.getName())) {

            /* here the main activity is calling activity*/

     }else{

             /*other activity is calling activity*/
  }
于 2016-04-01T06:40:05.257 回答