Reputation: 343
For every activity which has a logical parent we define that parent Activity in the Manifest like so:
<activity
android:name=".ui.activity.MyActivity"
android:label="@string/activity_title"
android:parentActivityName=".ui.activity.ParentActivity"
android:theme="@style/My.Theme" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.activity.ParentActivity" />
</activity>
Is there a way to access the Class referenced in either @parentActivityName
or meta-data@value
in MyActivity?
(Please note that I don't want to access the parent Activity instance, just the Class)
The reason is that for tracking purposes we want to generate a path-like String for each Activity. In this case this String would be /parent_activity/my_activity
– and since the hierachy is already defined in the Manifest, best case would be to access it there then to define it twice.
Thank you for your help!
Upvotes: 0
Views: 93
Reputation: 4910
Maybe it will help you NavUtils.getParentActivityName(childActivityInstance)
Upvotes: 1
Reputation: 2643
You could always go with the easy way: Pass the parent activity name in intent extras as string, in ParentActivity
Intent intent = new Intent(ParentActivity.this, ChildActivity.class);
intent.putExtra("parent_activity_name", "ParentActivity");
...
startActivity(intent);
And then get it in the ChildActivity activity
Intent intent = getIntent();
String parentName = intent.getStringExtra("parent_activity_name");
Not sure if there is any other more elegant solution.
Upvotes: 0