0

I am trying to appny immersive mode in one of my fragment, which in managed by a viewPager.

My fragment looks like:

public class MapFragment extends Fragment {
  private MapView mMapView;
  private GoogleMap googleMap;
  private UiSettings mUiSettings;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_map, container, false);

    mMapView = rootView.findViewById(R.id.mapView);
    mMapView.onCreate(savedInstanceState);
    if (getArguments() != null) {
      latlang.Lat = getArguments().getDouble("loclat");
      latlang.Lang = getArguments().getDouble("loclang");
    } else {
      latlang.Lat = 23.1;
      latlang.Lang = 79.9864;
    }
    rootView.setSystemUiVisibility(SYSTEM_UI_FLAG_IMMERSIVE
        | SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | SYSTEM_UI_FLAG_LAYOUT_STABLE
        | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | SYSTEM_UI_FLAG_FULLSCREEN
    );
...

Though this works, this is applying to all fragment (i.e. all tabs in the viewPager), which is not intended. So I have 2 question:

  1. Even when I am applying this specifically to a private view, how is it affecting other view?
  2. I have tried to manually clean the tags in onDestroy method, so that other fragments are not affected, which is not working either.

What I am doing wrong here?

@Override
  public void onDestroy() {
    super.onDestroy();
    mMapView.onDestroy();
    showSystemUI();
  }

  private void showSystemUI() {
    View  decorView = getActivity().getWindow().getDecorView();
    decorView.setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_STABLE
    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
  }
BaRud
  • 3,055
  • 7
  • 41
  • 89
  • The method `onDestroy()` is notorious for not getting called. You cannot rely on it. – Barns Jan 05 '20 at 16:07
  • So what is the alternatives? – BaRud Jan 05 '20 at 16:10
  • For starters I would at least try to toggle the UI somewhere in your fragment code to see if the effect you are seeing can be eliminated--perhaps manually or in the `onPause()` method. – Barns Jan 05 '20 at 16:16

0 Answers0