title: Optimization of service running with a continuously executing TimerTask
body: <p>I need a service that should always be running till its stopped explicitly by my activity  and should start again even if it is stopped due to some issue (<code>START_STICKY</code> flag). This service should continuously do something (every couple of seconds) using a <code>TimerTask</code>. I ended up with the following code.</p>
  
  <pre><code>public class SomeService extends Service {
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  
      TimerTask timerTask;
      final Handler handler = new Handler();
      Timer timer = new Timer();
  
      @Override
      public void onCreate() {
          // code to execute when the service is first created
          super.onCreate();
      }
  
      @Override
      public void onDestroy() {
          // code to execute when the service is shutting down
          super.onDestroy();
      }
  
      @Override
      public void onStart(Intent intent, int startid) {
          // code to execute when the service is starting up
          timerTask = new TimerTask() {
              public void run() {
                  handler.post(new Runnable() {
                      public void run() {
                                     //KEEP RUNNING SOME ERRANDS HERE
                          }
                      }
                  });
              }
          };
          timer.scheduleAtFixedRate(timerTask, 100L, 1700L);
      }
  
  }
  </code></pre>
  
  <p>Is there anyway that I can optimize this to run continuously? </p>