onCreateView () w Fragment nie jest wywoływany natychmiast, nawet po FragmentManager.executePendingTransactions ()
Czytałem, że jeśli musimy natychmiast utworzyć fragment, musimy zadzwonićexecutePendingTransactions()
metoda naFragmentManager
. To właśnie staram się robić. Lubię to:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.layout.fragmentContainer, new MyFragment);
fragmentTransaction.commit();
fragmentManager.executePendingTransactions();
foo(); // It is called before MyFragment's onCreateView()
}
Chciałbym wiedzieć dlaczegofoo()
metoda nazywa się PRZEDMyFragment
jestonCreateView()
. Jak widzisz, dzwonięexecutePendingTransactions()
w wątku interfejsu użytkownika, jaki powinien być. Nie mam tu nic wspólnego z wątkami.