Friday, 15 August 2014

java - onCreateView() in Fragment is not called immediately, even after FragmentManager.executePendingTransactions() -


I have read that if we need to immediately make a piece, then we should execute the executePendingTransactions () method Calling on Fragment Manager . Okay, I'm trying to do this. Like this: @ Override Protected Zero (Bundle Saved Instantstate) {Super. Secret (Saved Instantstate); SetContentView (R.layout.activity_game); Piece Manager Piece Manager = getFragmentManager (); Piece Transaction Piece Transaction = Piece MANAGER.beginTransaction (); FragmentTransaction.add (R.layout.fragmentContainer, new MyFragment); FragmentTransaction.commit (); FragmentManager.executePendingTransactions (); Foo (); // It is said before MyFragment'sCreateView ()}

I should know why the foo () method is MyFragment 's onCreateView () . As you see, I'm calling executePendingTransactions () in the UI thread as it should be, I'm not messing around with the thread here. I was involved in the same problem and I came to know that if I run the same piece, The method worked as a hope of execution, I know that there is not enough information about Android View Lifecycle, why this is the case.

  public void onStart () {Fragment Manager Slice Manager = getFragmentManager (); Piece Transaction Piece Transaction = Piece MANAGER.beginTransaction (); FragmentTransaction.add (R.layout.fragmentContainer, new MyFragment); FragmentTransaction.commit (); FragmentManager.executePendingTransactions (); Foo (); // should now work properly}    

No comments:

Post a Comment