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

What is the difference between Android Timer...

Câu trả lời

The main differences between using an Android Timer and a Handler to perform an action every N seconds are:

  1. Execution thread: A Timer executes the task on a separate thread, while a Handler executes the task on the thread it is associated with (usually the main UI thread)[1][3].

  2. Precision: A Handler is more precise in scheduling tasks compared to a Timer. Timers can suffer from time drift due to the time it takes to execute the task[1][2].

  3. Cancellation: It is easier to cancel a scheduled task with a Handler by removing the Runnable. With a Timer, you need to keep track of the TimerTask instance to cancel it[2].

  4. Overhead: Creating a new Handler has less overhead than creating a new Timer and TimerTask[2].

  5. Looper: A Handler requires a Looper to function, which can be the main Looper or a custom Looper. A Timer does not require a Looper[3]...

senior

senior

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

middle

What is RenderScript and when should we (really) use it?

middle

Explain how HashMap works

expert

What is the onTrimMemory method?

Bình luận

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

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