What is the difference between Android Timer and a Handler to do action every N seconds?
What is the difference between Android Timer and a Handler to do action every N seconds?
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).
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.
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.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.