user2229066 user2229066 - 5 months ago 11
Java Question

How do I change the hierarchy parent of an activity?

At the moment it is main activity but I want to change it to the Categories activity.
Is this where the problem lies?

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);

Answer

Go to AndroidManifest.xml, find your Sport activity and add this code

<activity android:name="Sport" >
    <meta-data
       android:name="android.support.PARENT_ACTIVITY"
       android:value="PARENT_ACTIVITY_PATH" />
</activity>

Substitute PARENT_ACTIVITY_PATH with the name of your parent activity adding also your package name (e.g. com.example.Categories).

Comments