Reputation: 163
I'm developing an app which has a navigation drawer. Although I don't have any previous experience with fragments I could implement navigation drawer successfully. Now my problem is, I want to have an Action Bar back button. I have tried this before for activities. But now the problem is I have a fragment which has a click event inside it. When the user clicks the button it goes to an activity which has list view inside it. Now I want to go back to the previous fragment using action bar up button. How can I do it? It's working properly when I press back button on my phone.
I have implemented onOptionsItemSelected as below in my list view activity. When I press action bar up button it goes to the login window. Not where I wanted it to go.
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
// Respond to the action bar's 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's task, so create a new task
// when navigating up, with a synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
// This activity is part of this app's task, so simply
// navigate up to the logical parent activity.
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}
Can anybody provide some help on the issue?
Upvotes: 5
Views: 12895
Reputation: 2370
I think in this post: Using ActionBar Up Navigation in master/detail fragments you can find you're answer for this problem.
I think you must working with the FragmentManager instead of the Activity.
Upvotes: 1