title: Background process timer on android
body: <p>I'm trying to get a process timer to run and keep it running in the background on android (starts with a button click).</p>
  
  <p>The timer must be on 30 seconds and should even continue growing application in the background (with home button and power / screen off).</p>
  
  <p>How can I do this? I tried with service and handler but not working ...</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My service tracking (process with 30 sec)</p>
  
  <pre><code>public class TrackingService extends IntentService {
  
      private Handler mHandler;
      private Runnable mRunnable;
  
      public TrackingService() {
  
          super("TrackingService");
  
      }
  
      public TrackingService(String name) {
  
          super(name);
  
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
  
          long timer = 30000;
  
          mHandler = new Handler();
          mRunnable = new Runnable() {
  
              @Override
              public void run() {
  
                      //TODO - process with update timer for new 30 sec
  
                      mHandler.postDelayed(this, timer);
  
              }
          };
  
          mHandler.postDelayed(mRunnable, timer);
  
      }
  
  }
  </code></pre>
  
  <p>My click button:</p>
  
  <pre><code>mButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
  
          //TODO - start first time and it continued every 30 seconds and continue in the background
          startService(Intent intent = new Intent(this, TrackingService.class));
  
      }
  });
  </code></pre>