Hi I am developing android application in which I am using I am using single Activity
and 3 fragments. So consider I have 3 fragments A B C. When I switch from A to
onResume()
of the Fragment
is called only when the Activity
is resumed. So this wont help you. Even I'm facing similar issue right now. You can implement OnBackStackChangedListener
and get the fragment name in the top of the stack and set the ActionBar
title based on that.
private FragmentManager.OnBackStackChangedListener getListener()
{
FragmentManager.OnBackStackChangedListener result = new FragmentManager.OnBackStackChangedListener()
{
public void onBackStackChanged()
{
FragmentManager manager = getFragmentManager();
if (manager != null)
{
if(manager.getBackStackEntryCount() >= 1){
String topOnStack = manager.getBackStackEntryAt(manager.getBackStackEntryCount()-1).getName();
Log.i("TOP ON BACK STACK",topOnStack);
}
}
}
};
return result;
}