Why is it recommended to use only the default constructor to create a Fragment ?
Why is it recommended to use only the default constructor to create a Fragment ?
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:
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.
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.
When performing Fragment transactions, such as adding, replacing, or removing Fragments, the Fragment manager expects the Fragments to have a default constructo...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào