2014-03-19 43 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. 
} 
} 
}