title: Hiding Navigation bar and Status Bar without flickering
body: <p>I am working on an Android App. I have a main_activity ,which shows a UI screen.
  I have hidden the Navigation Bar and Status bar for this activity using the following code :- </p>
  
  <pre><code>decorView = getWindow().getDecorView();
          final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
          // This work only for android 4.4+
          getWindow().getDecorView().setSystemUiVisibility(flags);
  
          // Code below is to handle presses of Volume up or Volume down.
          // Without this, after pressing volume buttons, the navigation bar will
          // show up and won't hide
          decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
              @Override
              public void onSystemUiVisibilityChange(int visibility) {
                  if((visibility &amp; View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
                  {
                      decorView.setSystemUiVisibility(flags);
                  }
              }
          });
  </code></pre>
  
  <p>It works Fine . When i launch my app , my main_activity gets called and it launches the app in full screen . But when it is launched the STATUS_BAR and NAVIGATION_BAR are momentarily shown and then they get hidden.
  THIS IS  OK FOR main_activity.</p>
  
  <p>BUT Now my main activity launches another activity .
  basically i click a Setting Button in my app , which launches a new activity.
  This new activity also needs to be in full screen . So i use the above mentioned code snippet to make it full screen.
  It goes full screen . But the NAVIGATION_BAR and STATUS_BAR are again momentarily shown . THIS IS NOT OK from user's perspective . Because my main_activity has already hidden the BARS ,so new activity should not show them even momentarily.</p>
  
  <p>I donot know how to achieve this . Your help is appreciated.
  thanks in advance. </p>
  
  <p>Here is how i launch my new_activity:-</p>
  
  <pre><code>private void shownewscreen() //new screen is basically setting screen
      {
          Intent intent = new Intent();
          intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          intent.setClass(this, newscreen.class);
          startActivity(intent);
      }
  </code></pre>
  
  <p>I use following code in the onCreate method of new activity to hide both the bars :-</p>
  
  <p>protected void makeWindowWithoutStatusNaviBar() {</p>
  
  <pre><code>decorView = getWindow().getDecorView();
  final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
          | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
          | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
          | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
      | View.SYSTEM_UI_FLAG_FULLSCREEN
          | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
          | View.STATUS_BAR_HIDDEN;
  // This work only for android 4.4+
  // Code below is to handle presses of Volume up or Volume down.
  // Without this, after pressing volume buttons, the navigation bar will
  // show up and won't hide
  decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
      @Override
      public void onSystemUiVisibilityChange(int visibility) {
          if((visibility &amp; View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
          {
              decorView.setSystemUiVisibility(flags);
          }
      }
  });
  </code></pre>
  
  <p>On Windows' focus change also i use following code in new activity:-</p>
  
  <pre><code>     onWindowFocusChanged(hasFocus) {
         super.onWindowFocusChanged(hasFocus);
          getWindow().getDecorView().setSystemUiVisibility(
                  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                  | View.STATUS_BAR_HIDDEN);
  }
  </code></pre>