M
M
Michael Kim2016-12-10 19:12:07
Java
Michael Kim, 2016-12-10 19:12:07

Why is onCreateView not executed after the fragment is added to the activity?

Here I am adding a fragment to the activity container:

fragmentManager.beginTransaction()
                .add(R.id.preview, previewFragment)
                .commit();
 Log.d("app", "2");

In fact, after adding a fragment, a call to onCreateView should occur:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.frament_photo_preview, container, false);
        Log.d("app", "0");
        return v;
}

And in the logs it should output:
app: 0
app: 2
But it outputs:
app: 2
app: 0
Is it because transactions associated with fragments are asynchronous? Or why?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question