2

I have this actual navigation tree :

A => B => C

According to configuration B can be skipped and the navigation become :

A => C

Whatever the case is , B stay C's parent.

So when i navigate to C (through B or not) i expect to reach B when i touch the up button of the action bar.

My manifest is defined like this :

 <activity android:name="my.package.A"></activity> 
 <activity android:name="my.package.B"></activity> 
 <activity android:name="my.package.C"
           android:parentActivityName="my.package.B"> 
 </activity>

My app targets android 4.1 and more , so no need for the <meta data> tag

C activity is set up like this:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_int);
    getActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId())
    {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}

So, according to the documentation, when i touch "up" B activity should be created or bringed back.

Problem :

When i skip B (going from A to C) , if i touch "up" the application is closing (because A has been finished, expected behavior) whereas it should create B.

In onOptionsItemSelected() shouldUpRecreateTask() always return false even if B does not exist.

If i navigate to C through B (A=>B=>C) the up button correctly bring back B.

What am i doing wrong ?

Thanks.

Community
  • 1
  • 1
grunk
  • 14,718
  • 15
  • 67
  • 108
  • try disabling this: getActionBar().setDisplayHomeAsUpEnabled(true); so replace true by false. haven´t tried but since you ahve your own functionality defined, you dont need to have the "up" implementation I guess – vandus Dec 11 '13 at 16:05
  • anyway, I would maybe use fragments instead of activities, your solution might become easier then. – vandus Dec 11 '13 at 16:10
  • 1
    disabling getActionBar().setDisplayHomeAsUpEnabled(true); will just remove the "up" button. If you want the up navigation you have to use that – grunk Dec 12 '13 at 08:13
  • I find the solution somewhat unique so I´d suggest implementing your own up button. But still, nowadays it´s better to use one activity and multiple fragments and it would be surely better for your app and it´s functionality. By the way, the up button in the action bar is used for fragments, not for activities... I am not 100% sure about that but I always use it for fragments. I call addToBackStack() on the fragmentTransaction and it adds the fragment to the backstack and when I press the "up" button, it goes back to the correct fragment. Think about that. – vandus Dec 12 '13 at 13:09
  • @vandus, The Up button can be used to go up the visula hierarchy. It doesn't matter whether the hierarchy consists of fragments or activities. – kpsfoo Apr 18 '14 at 12:31
  • 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:29

0 Answers0