我正在开发一个应用程序,但我需要运行一个函数x分钟,我已经尝试使用
scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(new Runnable() {
@Override public void run() {
Toast.makeText(ser, "Servicio MyService update", Toast.LENGTH_LONG).show();
}
},
0,
100,
TimeUnit.MILLISECONDS );
}
但它不起作用。 我在服务上使用此功能,当服务运行时,它不会调用该函数。
答案 0 :(得分:0)
如果我理解错了请纠正我, 你可以使用递归函数,
public void myfunc()
{
new CountDownTimer(70000, 1000) {
public void onTick(long millisUntilFinished) {
//
}
public void onFinish() {
Toast.makeText(getApplicationContext(), "7 seconds have passed",
Toast.LENGTH_LONG).show();//you can do here what you want every x(7)time
//you can put condition here to break recursive
myfunc(); //this calls again.
}
}
}
答案 1 :(得分:0)