What is the difference between Android Timer...
What is the difference between Android Timer...
The main differences between using an Android Timer and a Handler to perform an action every N seconds are:
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].
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].
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].
Overhead: Creating a new Handler has less overhead than creating a new Timer and TimerTask[2].
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
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào