I have FragmentA and FragmentB and have a problem with setting the title of my Activity when FragmentA becomes back visible.
Flow
getActivity().getSupportFragmentManager().popBackStack();
Now When FragmentA is back visible, the title of the Activity must be changed again like, FragmentA title = "A", FragmentB title = "B". But when FragmentA is back visible, the title is still "B" because onResume isn't called in FragmentA. What are my options to always set title to "A" in FragmentA is visible.
Code:
FragmentA
@Override
public void onResume() {
super.onResume();
getActivity().setTitle("POI's");
}
FragmentB
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
...
getActivity().setTitle("POI");
...
}
I tested on a single Activity with two fragment which worked fine. See the below code.
Fragment A : which show the app name
@Override
public void onResume() {
super.onResume();
getActivity().setTitle(R.string.app_name);
}
Fragment B : which show the app name
@Override
public void onResume() {
super.onResume();
getActivity().setTitle("fragment B");
}
Fragment A to B transaction Code :
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.container,new FragmentB())
.addToBackStack(null)
.commit();
Update:
Need to replace fragment like "replace(R.id.container,new FragmentB())
" rather than add it to FragmentManager to change title of a activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With