Back to project page CakeUI.
The source code is released under:
GNU General Public License
If you think the Android project CakeUI listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.cakeui.generic.service; //from w w w . j ava 2 s. com /** * Class that implements a generic service that is executed periodically. * Initially, is set to execute the task once per minute, but the time interval can be changed. * * @author Sarah Caixeta * @email caixeta.sarah@gmail.com * */ public class CakePeriodicService extends CakeService implements Runnable{ private static final long ONE_MINUTE = 60000; private Thread syncThread; private long interval = ONE_MINUTE; @Override public void onCreate() { super.onCreate(); startThread(); } public void startThread() { if (syncThread == null){ syncThread = new Thread(this); syncThread.start(); } } @Override public void run() { while (true) { try { performTask(); Thread.sleep(interval); } catch (InterruptedException e) { e.printStackTrace(); } } } public void setTimeInterval(long timeMillis){ this.interval = timeMillis; } public long getTimeInterval(){ return this.interval; } }