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

senior

What is the difference between Android Timer and a Handler to do action every N seconds?

entry

What is the difference between Bitmap and Drawable in Android?

senior

Discuss Singletons vs. Application Context for app-global state

Bình luận

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

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