What are Retained Fragments?
What are Retained Fragments?
Retained fragments are a way to preserve the state of a fragment across configuration changes, such as screen rotations, in Android. When a fragment is marked as retained, the Android system will not destroy it when the hosting activity is re-created due to a configuration change.
To make a fragment retained, you call setRetainInstance(true) in the fragment's onCreate() method. This tells the Android system to keep the fragment alive and not destroy it, even if the hosting activity is destroyed and re-created.
Retained fragments are useful for preserving long-running operations or complex state that should not be lost when the activity is re-created. For example, you might use a retained fragment to hold a reference to an AsyncTask or a network connection that should continue running despite configuration changes.
Đă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.