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

Explain reasons why not to ...

Câu trả lời

Here are the main reasons why you should avoid using getApplicationContext() in Android development:

1. Limited Lifecycle

The Application context returned by getApplicationContext() has a longer lifecycle than an Activity or Fragment context. It exists for the entire duration of the app process, even if all activities are destroyed. This can lead to memory leaks if you hold onto references to the Application context in places where it outlives the intended scope.

2. No Lifecycle Callbacks

Unlike Activity and Fragment, the Application class does not have lifecycle callbacks like onCreate(), onStart(), onResume(), etc. This makes it harder to properly manage resources and subscriptions tied to the Application context.

3. Lack of Configuration Changes

When the device configuration changes (e.g. screen rotation, language change), Activity and Fragment instances are recreated, but the Application instance persists. T...

expert

expert

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 ?

entry

Mention the difference between RelativeLayout and LinearLayout ?

middle

What does LayoutInflater in Android do?

Bình luận

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

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