简体   繁体   English

Android上的实时计时器

[英]Real-time timer on Android

In what way that I can have a real-time timer for task scheduling on Android? 我可以通过哪种方式在Android上使用实时计时器进行任务调度?

Currently I am using Java.util.timer for my real-time application? 目前,我正在为实时应用程序使用Java.util.timer吗? However, the timer is missing firing when garbage collection is running or other other stuff. 但是,运行垃圾回收或其他其他东西时,计时器缺少触发功能。 The description on java.util.timer says "this class does not offer guarantees about the real-time nature of task scheduling.". 关于java.util.timer的描述说:“此类不提供有关任务调度的实时性的保证。” Then, which class that I should use on Android then? 然后,我应该在Android上使用哪个类? Or are there any other approach to have a real-time guarantee timer on Android? 还是有其他方法可以在Android上设置实时保证计时器?

Forgot to mention that the timer that I need is at 20 - 40 milliseconds precision level. 忘了提到我需要的计时器的精度是20-40毫秒。 That means, I need it to fire every 20 - 40 milliseconds. 也就是说,我需要它每20-40毫秒触发一次。

Handler.postDelayed(Runnable r, long delayMillis);

Does not have a note about whether or not it guarantees it to happen on time. 没有关于它是否保证按时发生的注释。 I've used this mechanism before and never noticed any inconsistency with it. 我以前使用过这种机制,但从未注意到它有任何不一致之处。 However, i've only used it for relatively short intervals (less than a minute) If you are looking for something farther out than that I would suggest you take a look at the AlarmClock application in the Android source. 但是,我只使用了相对较短的时间间隔(不到一分钟),如果您正在寻找比这更远的东西,我建议您看看Android源代码中的AlarmClock应用程序。 That will probably give you a good approach. 那可能会给你一个很好的方法。 That being said if you are looking for extreme precision(down to seconds or farther) I doubt you're going to be able to find anything with guarantees. 话虽这么说,如果您正在寻找极高的精度(低至几秒或更远),我怀疑您将能够找到有保证的东西。 There are too many things that could be going on that could cause potential misfires. 可能发生的事情太多,可能导致潜在的失火。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM