Jim
Jim

Reputation: 19562

Can we know the class name of the activity that started the current?

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?

Upvotes: 0

Views: 96

Answers (1)

Jordi Castilla
Jordi Castilla

Reputation: 26961

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");

Upvotes: 2

Related Questions