本文介绍了在执行某些小时功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在执行由TimePicker挑特定时间的一些功能。

I want to execute some function at specific hour picked by TimePicker.

我可以使用处理程序是这样的:

I can use Handler like this:

Handler myHandler = new DoSomething();
Message m = new Message();
myHandler.sendMessageDelayed(m, delay);

class DoSomething extends Handler {
    @Override
    public void handleMessage(Message msg) {
      MyObject o = (MyObject) msg.obj;
      //do something here
    }
}

和加载的延迟参数:picked_wanted_hour - current_hour
或者在某个时间间隔检查当前时间和调用该函数在时机成熟时。

And load the "delay" param with: picked_wanted_hour - current_hourOR check for the current time at some interval and invoke the function when the time comes.

不过,有没有处理状物体,可以采取特定的时间和当时调用操作?

But, is there any handler-like object that can take a specific time and invoke the operation at that time?

先谢谢了。

推荐答案

你为什么不使用处理程序本身?只是通过 timePickerTime - currentTime的作为延迟结果
 还有与方法时间表(TimerTask的任务,年月日时)

Why don't you use handler itself? Just pass timePickerTime - currentTime as a delay.
There's also Timer with method schedule(TimerTask task, Date when).

这篇关于在执行某些小时功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 11:18