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.
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.
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.
Đă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.