0

In my app I have created a generic activity, all activities in my app inherit from this activity. The idea behind is having a common code for several activities. In particular the actions from the menu in the action bar.

So far, I am concerned now with the up button in the action bar. Some activities in my app logic have got a clear parent activity, so far so good. However some other activities can be called by different activities. For these activities I want the behaviour to be like the back button.

The solution for making the up button to behave as the back button is to implement at the method onOptionsItemSelected the behaviour of the up button as back, like this:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
       @Override
       onBackPressed();
       return true;
    }
return super.onOptionsItemSelected(item);
}

The problem I have, is that if I implement this all activities will behave as the back button. I prefer to control that on those I have a clear parent (just in case). So I prefer to implement and "if", like "If I ask for back button" (boolean I will use) use function "onBackPressed", "else" use normal behaviour.

The problem, is that I don't know how to reproduce the behaviour of Up button with a function. I tried hard looking in google...

So... does somebody knows about a function like... "onUpPressed" so that I can control both behaviours?

Trebia Project.
  • 930
  • 2
  • 17
  • 36

1 Answers1

0

Answer duplicated, using the right keywords what I wanted to do is described here:

ActionBar Up button and Navigation pattern

Community
  • 1
  • 1
Trebia Project.
  • 930
  • 2
  • 17
  • 36