Steady, accurate timing in Android

左心房为你撑大大i 提交于 2019-12-06 06:20:47

I don't think "hard realtime" programming is possible. The options seem to be to look for events that signal when something has happened. This can be done by creating your own flag, and polling for the value of that flag in the other thread.

You can use a CountDownTimer to specify a particular length of time must pass in millis.

You can use the System clock and make your own timer, by polling on how much time has passed.

There is also a useful class called FileObserver that allows you to watch a particular file, and hear the events like Opened, and Closed. Using those signals you can know that it is time to move to the next operation.

The worst possible bug is that there is a timing issue that occurs on a specific piece of hardware but doesn't happen on most. The problem if that I don't own all of them, and finding the timing issue is tough. I'm hoping that others will have a better - or more - answers for this issue.

After much googling I managed to find the answers here:

http://masterex.github.com/archive/2012/05/28/android-audio-synthesis.html

Handlers, Thread.sleep() and timers are not the way to go it seems.

Thank you DrA for your answer, it was appreciated - sorry for not acknowledging sooner, I've been away for a while.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!