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

When is it necessary, or better to use a SurfaceView instead of a View ?

senior

What are some differences between ART and Dalvik?

junior

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

Bình luận

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

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