SetTitle when fragment is visible again

I have FragmentA and FragmentB and have problems setting the title of my activity when FragmentA becomes visible.

Flow

  • FragmentA Visible (not added to backstack)
  • add FragmentB (added to backstack)
  • the back button is pressed, not the default implementation, but it needs to be captured in the Fragment, but I do getActivity().getSupportFragmentManager().popBackStack();

Now that FragmentA is visible again, the Activity header should be changed again, for example, FragmentA title = "A", FragmentB title = "B". But when FragmentA is visible again, the name is still "B" because onResume is not called in FragmentA. What are my possibilities to always set the title to “A” in FragmentA is visible.

the code:

Fragmenta p>

@Override
public void onResume() {
        super.onResume();
        getActivity().setTitle("POI's");       
}

Fragmentb

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
        ...
        getActivity().setTitle("POI");
        ...
}
+4
2

, . . .

A:

@Override
public void onResume() {
    super.onResume();
    getActivity().setTitle(R.string.app_name);
}

B:

@Override
public void onResume() {
    super.onResume();
    getActivity().setTitle("fragment B");
}

-:

getActivity().getSupportFragmentManager().beginTransaction()
            .replace(R.id.container,new FragmentB())
            .addToBackStack(null)
            .commit();

Update: "replace(R.id.container,new FragmentB())", FragmentManager, .

+10

getActivity().getActionBar().setDisplayShowTitleEnabled(true);

getActivity().getActionBar().setTitle("your title");
+2

All Articles