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

Why is it recommended to use only the default constructor to create a Fragment ?

Câu trả lời

Here is the answer to your Android interview question:

It is recommended to use only the default constructor to create a Fragment for the following reasons:

Consistency with Fragment Lifecycle

The Fragment class expects a default constructor to be present. This is because the Fragment class internally uses the default constructor when creating a new instance of the Fragment during the Fragment lifecycle, such as when restoring the Fragment state after device rotation.

Avoid Potential Issues

If you create a Fragment using a custom constructor, it may lead to potential issues when the Fragment is restored from the saved state. The Fragment manager may not be able to properly instantiate the Fragment using the custom constructor, leading to crashes or unexpected behavior.

Compatibility with Fragment Transactions

When performing Fragment transactions, such as adding, replacing, or removing Fragments, the Fragment manager expects the Fragments to have a default constructo...

junior

junior

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

middle

What is the difference between Handler vs AsyncTask vs Thread ?

middle

What is the actual differences between a Activity Context and Application Context?

middle

What is DDMS and what can you do with it?

Bình luận

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

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