处理器postDelayed拖延更长的配置 [英] Handler postDelayed delayed longer as configured
问题描述
我尝试开发一个简单的定时器蜂鸣器,即窥视小时。对于时序我用一个服务和处理程序,这里的例子:
I try to develop a simple timer beeper, that peep hourly. For the timing I use a Service and handler, here the example:
void onStart(...){
handler.postDelayed(timerRunnable, ONE_HOUR);
}
private Runnable timerRunnable = new Runnable() {
@Override
public void run() {
...beep
handler.postDelayed(timerRunnable, ONE_HOUR);
}
};
不过的的run()的方法将被解雇不确定的,我认为这是依赖从目前的设备使用情况。
but run() method will be fired nondeterministic, I think it is dependent from the current device usage.
我已经尝试了同样的场景,TimerTask的,并与manualy'线程执行,但具有相同的不确定的结果。
I have try the same scenario with TimerTask and with 'manualy' Thread implementation, but with the same nondeterministic result.
推荐答案
你可能有更好的运气使用 AlarmManager
这么长时间的延迟。 处理程序
是最好的蜱和超时而你的应用程序是在前台。
You'll probably have better luck using the AlarmManager
for such a long delay. Handler
is best for ticks and timeouts while your app is in the foreground.
http://developer.android.com/reference/android/app/ AlarmManager.html
这篇关于处理器postDelayed拖延更长的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!