Search code examples
javaandroidandroid-intentandroid-activity

Getting launcher activity class name


Is there a way to get the class name of the activity that launched the Intent without putting extras to the Intent?

I use the following code to launch other activities.

Intent intent = new Intent(CallerClass.this, TargetClass.class);
startActivity(intent);

Can I get the caller class' name in the target class?


Solution

  • One way you could do it is by using startActivityForResult() instead of startActivity(Intent) and then have the second activity use getCallingActivity() to get the CallerClass.