Android fragment replace(...) on thread
<p>Can someone explain me why replacing fragment on thread causes sometimes blank space instead of showing the fragment on screen?</p>

<pre><code>public void swapFragment(final CustomFragment fragment) {

    new Thread(new Runnable() {
        @Override
        public void run() {
            FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
            ft.replace(R.id.fragment_container, fragment, fragment.getName());
            ft.addToBackStack(fragment.getName());

            ft.commit();
        }
    }).start();

}
</code></pre>

<p>Let me explain what is happening:</p>

<p>1) I have no fragment added inside my container. </p>

<p>2) I'm adding fragment <strong>A</strong> using this method - its working</p>

<p>3) Then I'm using this method to swap actual fragment <strong>A</strong> with my fragment <strong>B</strong> - its working</p>

<p>4) But when I'm trying to swap it with new instance (<strong>!!!</strong>) of fragment <strong><em>A</em></strong> it leaves blank space</p>

<p>I know that i can do it on main thread, but this is just an example. I'm dealing with different issue, but my issue is more complex to explain.</p>

<h1>EDIT :</h1>

<p>at point 4) I placed wrong fragment - it was ment to be "<em>fragment A</em>"</p>