I have an Activity
where I load in a ListFragment
and, upon clicking, it drills down a level and a new type of ListFragment
is shown,
As the original answer is quite old, this might come of help as well. As the documentation states, one might want to register a listener
to listen on the back stack changes in the hosting Activity
:
getSupportFragmentManager().addOnBackStackChangedListener(
new FragmentManager.OnBackStackChangedListener() {
public void onBackStackChanged() {
// Update your UI here.
}
});
Then, identify the situation in the callback method and set a proper title, without accessing the ActionBar
from the Fragment
.
This is a more elegant solution as the Fragment
doesn't have to know about the ActionBar
existence and Activity
is usually the place that is managing the backstack so having it handled over there seems to be more appropriate. Fragment
should at all time be considered only by its own content, not the surroundings.
More on the topic in the documentation.