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

What is the difference between Activity and Context ?

Câu trả lời

The main differences between Activity and Context in Android are:

  • An Activity is a subclass of Context, while Context is a base class that provides access to application-specific resources and classes[1][2].

  • Activity context is tied to the lifecycle of an Activity and is destroyed when the Activity is destroyed, while Application context lasts for the entire lifetime of the application[1][2][3].

  • Activity context should be used for UI-related operations like inflating layouts, starting activities, showing dialogs, etc. Application context should be used for global, non-UI operations like accessing shared preferences, caching data, etc.[2][4]

  • Passing an Activity context to a long-lived object like a Singleton can cause memory leaks, so Application contex...

middle

middle

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

expert

What is the relationship between Looper , Handler and MessageQueue in Android?

junior

What is Context on Android?

middle

What is Handler and what is it used for?

Bình luận

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

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