Action bar UP Navigation Activity in fragment

I am developing a navigation box application. Although I have no previous experience with fragments, I could successfully implement the navigation box. Now my problem is that I have a return button to the action bar. I tried this before for classes. But now the problem is that I have a fragment in which there is a click event inside it. When the user clicks the button, he goes to an activity in which there is a list view. Now I want to go back to the previous snippet using the action bar button. How can I do it? It works correctly when I press a button on my phone.

I have included onOptionsItemSelected as shown below in my list view activity. When I press the up button, it goes to the login window. Not where I wanted him to go.

public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    // Respond to the action bar Up/Home button
    case android.R.id.home:
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is NOT part of this app task, so create a new task
            // when navigating up, with a synthesized back stack.
            TaskStackBuilder.create(this)
                    // Add all of this activity parents to the back stack
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent
                    .startActivities();
        } else {
            // This activity is part of this app task, so simply
            // navigate up to the logical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

Can someone help in solving the problem?

+4
source share
1 answer

I think in this post: Using ActionBar Up Navigation in fragments of the wizard / part , you can find the answer to this problem.

I think you should work with FragmentManager instead of Activity.

+1
source

All Articles