2014-03-19 16 views
0

我正在开发一个应用程序,但我需要运行一个函数x分钟,我已经使用运行功能,服务好每一位×时间的Android

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

,如果我理解错了请纠正我, 可以使用递归FUNC,

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. 
} 
} 
}