Take the 2-minute tour ×

I have an android app, I'm moving to fragment based design.

The main activity is a list fragment, that displays one of several detail fragments when an item is selected. One of the detail fragments is a list, which opens a new detail activity on an android phone. I'd like to use the app icon as a back button, however, it goes all the way back to my root activity and displays the first list, not the second.

The handset back button does the right thing, and just goes back one level. How can I fix the onOptionsItemSelected method to just go back to the last fragment, not the root fragment?

Thanks, Gerry

share|improve this question

1 Answer 1

up vote 0 down vote accepted

use return followed by finish()


That will finish current activity and return to the previous one.

share|improve this answer

Your Answer


