Câu hỏi phỏng vấn Android
Câu hỏi

What are the differences between onCreate() , onCreateView() , and onActivityCreated() in Fragments
and what would they each be used for?

Câu trả lời

The main differences between onCreate(), onCreateView(), and onActivityCreated() in Android Fragments are:

  1. onCreate(Bundle savedInstanceState):

    • Called when the fragment is first created[1][3].
    • Used for basic initialization, such as creating views and binding data to lists[3].
    • The fragment's view hierarchy is not yet created when this method is called[3].
  2. onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState):

    • Called to have the fragment instantiate its user interface view[3].
    • Responsible for inflating the fragment's layout using the provided LayoutInflater[3].
    • Returns the View for the fragment's UI, or null if the fragment does not provide a UI[3].
  3. onActivityCreated(Bundle savedInstanceState):

    • Called when the fragment's activity has been created and this fragment's view hierarchy instantiated[3].
    • Allows you to do final initialization based on what you have in the activity[3].
    • At this point, it is safe to search for activity views by t...
middle

middle

Gợi ý câu hỏi phỏng vấn

junior

What is the Dalvik Virtual Machine?

middle

Why Fragments, and when to use Fragments instead of Activities?

entry

Mention the difference between RelativeLayout and LinearLayout ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào