Can someone explain me why replacing fragment on thread causes sometimes blank space instead of showing the fragment on screen?
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();
}
Let me explain what is happening:
1) I have no fragment added inside my container.
2) I'm adding fragment A using this method - its working
3) Then I'm using this method to swap actual fragment A with my fragment B - its working
4) But when I'm trying to swap it with new instance (!!!) of fragment A it leaves blank space
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.
EDIT :
at point 4) I placed wrong fragment - it was ment to be "fragment A"