title: android, how to avoid the flick when replace fragment with FragmentTransaction after did the popStack first
body: <p>when adding fragments in the activity, it is done by <code>replace(R.id.fragment_container, theFragment, backStackTag)</code>.</p>
  <p>the use case is to limit the FragmentTransaction in the backstack, i.e.</p>
  <p><code>[a]-&gt;[b]-[c]-&gt;[d]-&gt;[e]</code>, if adding one more <code>[f]</code>, it should pop <code>[e]</code> first so the result would be:</p>
  <p><code>[a]-&gt;[b]-[c]-&gt;[d]-&gt;[f]</code></p>
  <p>and the code: does <code>supportFragmentManager.popBackStackImmediate()</code> first to pop the <code>[e]</code>, and then do <code>.replace(R.id.fragment_container, theFragment, backStackTag)</code> to show the <code>[f]</code>.</p>
  <p>but it will show a flick with content of <code>[e]</code> before the <code>[f]</code> is displayed.</p>
  <p>is there a way to avoid this flickering?</p>
  <pre><code>        val theFragment = getFragment()
          if (supportFragmentManager.backStackEntryCount &gt; MAX_STACK_DEPTH) {
               supportFragmentManager.popBackStackImmediate()
          }
          supportFragmentManager.beginTransaction()
                          .addToBackStack(backStackTag)
                          .replace(R.id.fragment_container, theFragment, backStackTag)
                          .commit()
  </code></pre>