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

What are some difference between Parcelable and Serializable ?

middle

What is the difference between onCreate() and onCreateView() lifecycle methods in Fragment ?

middle

What is Intent Filter?

Bình luận

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

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