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

What is the actual differences between a Activity Context and Application Context?

Câu trả lời

The main differences between Activity Context and Application Context in Android are:

  1. Lifecycle: Activity Context is tied to the lifecycle of a specific Activity and is destroyed when that Activity is destroyed. Application Context is tied to the lifecycle of the entire Application and persists until the Application is terminated[1][2].

  2. Accessibility: Activity Context can only be accessed from within the Activity it is associated with. Application Context can be accessed from anywhere in the Application[1][3].

  3. Resource Access: Activity Context provides access to resources that are specific to the Activity, such as layouts, widgets, and themes. Application Context provides access to global resources that are not tied to any specific Activity[1][3].

  4. Memory Usage: Using Application Context instead of Activity Context can prevent memory leaks, as the Application Context has a longer lifespan and is not tied to the Activity lifecycle[2][4].

  5. Functionality: Activity Context is use...

middle

middle

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

expert

What is Intent vs Sticky Intent vs Pending Intent ?

senior

What is a Sticky Broadcast ?

senior

Can you manually call the Garbage collector?

Bình luận

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

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