Reputation: 4173
Here is what I do to create a new fragment (called AlbumsTrackFragment
) and replace the existing one :
AlbumsTrackFragment albumstrackfragment = new AlbumsTrackFragment();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.layout_ipod, albumstrackfragment, "albumsTrackfragment");
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
albumstrackfragment.DoTask(data);
The problem is that when I can't call the method DoTask()
and pass the new fragment some data because the app crashes, indeed I get : Content view not yet created
How can I wait that the commit
was performed to call DoTask()
method of my fragment ?
Thanks
Upvotes: 1
Views: 470
Reputation: 5552
You might consider passing in data to your fragment through DoTask and then wait until OnActivityCreated() is called to perform whatever action happens in DoTask. This way you are passing in your data but not doing anything until your view is loaded and won't crash.
Upvotes: 3