7

I would like to compare the calling activity to others to know which one called the current activity. I tried:

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

It doesn't work, except by passing a value in the calling Intent, how can we compare classes using getCallingActivity() or getCallingPackage()?

Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
Jerec TheSith
  • 1,932
  • 4
  • 32
  • 41

1 Answers1

9

You can compare the calling activity in the following manner if the activity is started for result from another activity.

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

            /* here the main activity is calling activity*/

     }else{

             /*other activity is calling activity*/
  }
Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55