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.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.