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

What are Retained Fragments?

Câu trả lời

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[1][2].

To make a fragment retained, you call setRetainInstance(true) in the fragment's onCreate() method[1][3]. This tells the Android system to keep the fragment alive and not destroy it, even if the hosting activity is destroyed and re-created[2].

Retained fragments are useful for preserving long-running operations or complex state that should not be lost when the activity is re-created[3]. 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[1].

It's important to note that while the fragment itself is retained, its view hierarchy is still destroyed a...

middle

middle

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

middle

What is the difference between AsyncTask and Thread/Runnable ?

junior

Is it possible to implement the Model–View–Controller pattern in Java for Android?

expert

What happens if the user navigates away or closes the app while I still have a reference to the Activity
the user just closed in my AsyncTask ?

Bình luận

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

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