Android

Android Lifecycle

Activity/Fragment Lifecycle, Configuration Changes and state management

30 câu hỏi phỏng vấn·
Junior
1

What is the correct lifecycle order of an Activity when starting?

Câu trả lời

An Activity's lifecycle starts with onCreate() (initialization and view creation), followed by onStart() (Activity becomes visible but not yet interactive), then onResume() (Activity in foreground and interactive). This sequence is always the same for each Activity start.

2

Which first lifecycle method is called when the Activity goes to background?

Câu trả lời

onPause() is the first method called when the Activity starts losing focus. It's followed by onStop() when the Activity is no longer visible at all. Critical data should be saved in onPause() as the system may kill the process after this method without calling onStop().

3

In which method should you initialize Views (findViewById, ViewBinding)?

Câu trả lời

onCreate() is the appropriate method to initialize Views as this is where setContentView() is called and the View hierarchy is created. Views are not yet available before onCreate(). You can also use onViewCreated() in Fragments.

4

What is the difference between onPause() and onStop()?

5

What happens during screen rotation by default?

+27 câu hỏi phỏng vấn

Nắm vững Android cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí