定时器和alarmmanager之间的区别 [英] difference between timer and alarmmanager

查看:133
本文介绍了定时器和alarmmanager之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑定时器 AlarmManager 在Android中使用。

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

什么是他们的之间的主要区别是什么?

What are the main differences between them?

他们都安排任务在每次秒运行。什么是主要的情况下,他们将要使用preferred?

They are both scheduling a task to run at every A seconds. And what is the main scenario that they are preferred to be used?

例如,对于x的情况下,使用定时器但另一方面,Y的情况下,使用 AlarmManager

For example, for X situation, use Timer but on the other hand, for Y situation, use AlarmManager.

推荐答案

A 定时器将启动一个线程,该线程将跟踪何时开始code的。如果该设备便睡着了,于是将计时器线程和你的code将不能按时执行。 AlarmManager 的报警,在另一方面,是内核级。取决于你如何注册它们,你可以要求唤醒设备,或执行下一次的东西唤醒设备。报警的普遍preferable并使用更少的资源。

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.

这篇关于定时器和alarmmanager之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆