LuckyLuke
LuckyLuke

Reputation: 49057

Replacing fragment does not work properly

I am replacing an fragment with the following code. Why isn't onCreateView invoked immediately after the commit? I am executing a Async task after this, however I get a nullpointerexception since the references in ResultListFragment is not resolved yet since the OnCreateView method hasn't been runned. Why? and how could I fix this?

if (mResultListFragment == null) {
    mResultListFragment = new ResultListFragment<Question>();
}

getFragmentManager()
    .beginTransaction()
    .addToBackStack("result")
    .replace(R.id.someContainer, mResultListFragment)
    .commit();

// AsyncTask stuff here

Upvotes: 1

Views: 59

Answers (1)

Matthew Mcveigh
Matthew Mcveigh

Reputation: 5685

Call FragmentManager's executePendingTransaction to block the main thread until your fragment has been committed, without calling this the commit is done asynchronously

Upvotes: 2

Related Questions