Reputation: 5092
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?
Upvotes: 3
Views: 1853
Reputation: 7203
String packageName = context.getPackageName();
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
String className = launchIntent.getComponent().getClassName();
Upvotes: 1
Reputation: 269
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
.
Upvotes: 2
Reputation: 531
use startActivityForResult then you can retrieve activity caller by : getCallingActivity().getClassName()
Upvotes: 1