2

I am trying to set Back option from one activity to other

  • Activity CategoryRegister has parent Register Activity .
  • Activity Register has parent LoginActivity

When I go back from wither of above I go back to login register , while for categoryregister activity I should go back to Register activity.

Part of manifest file:

<activity
    android:label="Login Account"
    android:name=".LoginActivity"></activity>
<activity
    android:label="Register New Account"
    android:parentActivityName=".LoginActivity"
    android:name=".RegisterActivity"></activity>
<activity
    android:label="Select Category"
    android:parentActivityName=".RegisterActivity"
    android:name=".CategoryRegister"></activity>

Procedure to setup back navigation :

getActionBar().setDisplayHomeAsUpEnabled(true);

@Override
public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.action_register:

            return true;
          break;
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
            default:
                   return true;
}

Thanks in advance . I really don't get this behavior . Did anyone face similar issues?

Using the above manifest its working for parent->child , but in case of parent->child1->child2 (child2 up button takes back to parent, but not child1 , which is parent of child2 as described in android manifest.

Harshit
  • 1,207
  • 1
  • 20
  • 40
  • Can you clarify whether you are referring to the up button or the back button? They are two distinct buttons that should have distinct functionality. Your code seems to indicate that you are referring to the up button, but your description refers to the back button. – Bryan Herbst Feb 10 '14 at 21:52
  • Button which is visible on action bar after getActionBar().setDisplayHomeAsUpEnabled(true); Up button – Harshit Feb 10 '14 at 21:53
  • You are not doing anything wrong. NavUtils is at fault here as NavUtils behaves differently pre JellyBean and post JellyBean. See my answer to similar question here, http://stackoverflow.com/a/23140158/238768 – kpsfoo Apr 18 '14 at 12:34

1 Answers1

1

What is the version of android you are using? If you are using 2.1 or less , you need meta tags for backwards compatibility. E.g

<activity
    android:name="someActivity"
    android:label="someLabel"
    android:parentActivityName="theParent">

    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="theParent" />

</activity>

Edit : if that is not the case have a look at this http://developer.android.com/design/patterns/navigation.html

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
Evdzhan Mustafa
  • 3,645
  • 1
  • 24
  • 40
  • Using the above manifest its working for parent->child , but in case of parent->child1->child2 (child2 up button takes back to parent, but not child1 , which is parent of child2 as described in android manifest – Harshit Feb 10 '14 at 22:05
  • @Evcan Mustafa is suggesting that you add the `` tag if you are supporting older versions of Android. What is your `minSdkVersion`? – Bryan Herbst Feb 10 '14 at 22:07
  • minSDK is 11 maxSDK is 18 – Harshit Feb 10 '14 at 22:10