Is there a way to know which activity class started another activity class other than passing the name of the class as an Extra
in the Intent
?
When we do new Intent(this, SomeOtherActivity.class)
is it possible to get the name of this
in the when we are in onCreate
of the SomeOtherActivity
?
Asked
Active
Viewed 87 times
0

HoldOffHunger
- 18,769
- 10
- 104
- 133

Jim
- 18,826
- 34
- 135
- 254
-
Seems like you are a duplicate of http://stackoverflow.com/questions/3304304/how-to-get-the-sender-of-an-intent - recommending close – Elemental Aug 28 '15 at 09:56
1 Answers
2
Create an instance and put an extra to the intent:
Intent i = new Intent(this, SomeOtherActivity.class)
i.putExtra("ACTIVITY_NAME", this.getClass().getName());
Retrieve it with:
Bundle extras = getIntent().getExtras();
String activityName = extras.getString("STRING_I_NEED");

Jordi Castilla
- 26,609
- 8
- 70
- 109
-
So the framework does not offer this information? I have to explicitly pass it? – Jim Aug 28 '15 at 08:15
-
AFAIK yes, you should because intent doesn't. Also cant find nothing in [Intent API](http://developer.android.com/reference/android/content/Intent.html). But not 100% sure... let's wait if there are other answers. Have you debugged @ `onCreate` searching for the context? – Jordi Castilla Aug 28 '15 at 08:21