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()
?
onCreate(savedInstanceState); setContentView(R. layout. main2); DataClass dc = new DataClass(); dc. show(); } public void call(ArrayList<String> arr) { // Some code... } }
If you start the activity with startActivityForResult(Intent, int) , then you can get calling activity by getCallingActivity(). getClassName() .
Typically, one activity in an app is specified as the main activity, which is the first screen to appear when the user launches the app. Each activity can then start another activity in order to perform different actions.
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*/
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With