What is the difference between Activity and Context ?
What is the difference between Activity and Context ?
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
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào