0

i am developing an app but i need run a function x minutes, i've tried using

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 );
}

but it does not work. i use this function on a service, when the service is running it does'not call the function.

4

1 回答 1

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.
 }
} 
}
于 2014-03-19T17:16:47.340 回答