Code example for ScheduledExecutorService

Methods: scheduleAtFixedRate

0
	 
	@Override 
	public int onStartCommand(Intent intent, int flags, int startId) {
		scheduler = Executors.newScheduledThreadPool(1);
        schedulerHandle = 
        	scheduler.scheduleAtFixedRate(
        		new Runnable() {
        			public void run() { 
        				Log.d("Datalogger", "service task");
        			} 
        		}, 0, 1, TimeUnit.SECONDS);
        super.onCreate(); 
        return START_STICKY;
	} 
	 
	@Override 
	public void onDestroy() { 
		super.onDestroy(); 
		//schedulerHandle.cancel(false); 
		scheduler.shutdown();
		Log.d("Datalogger", "Service destroyed!");