Compare activity from getCallingActivity to another

I would like to compare challenging activity with others to find out which one is called current. I tried:

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

This does not work except passing the value in the calling Intent, how can we compare classes using getCallingActivity() or getCallingPackage() ?

+4
source share
1 answer

You can compare the calling activity as follows if the action is triggered for the result of another action.

  if (getCallingActivity().getClassName().equals(MainActivity.class.getName())) { /* here the main activity is calling activity*/ }else{ /*other activity is calling activity*/ } 
+5
source

All Articles