difference between timer and alarmmanager

后端 未结 2 929
一个人的身影
一个人的身影 2020-12-28 16:07

I am a bit confused about Timer and AlarmManager used in Android.

What are the main differences between them?

They are b

相关标签:
2条回答
  • 2020-12-28 16:54

    A Timer will start a thread that will keep track of when to start your code. If the device goes asleep, so will the timer thread and your code won't be executed on time. AlarmManager's alarms, on the other hand, are kernel-level. Depending on how you register them, you can request to wake up the device, or execute the next time something wakes up the device. Alarm's are generally preferable and use less resources.

    0 讨论(0)
  • 2020-12-28 17:08

    Timer starts a service it executes code very frequently even thought it wasn't actually doing anything.

    Alarmmanager on the other hand will start a Service that runs in the background always, this is what you want to use to schedule your code to run when your app isn't open.

    0 讨论(0)
提交回复
热议问题