title: How to start/stop Runnable/Handler?
body: <p>I'm trying to maintain databases synchronized between a Webservice and Android app.
  The code below is working, but I encounter some problems:</p>
  
  <ul>
  <li>Every time I go to main page of App a new infinite process is started.</li>
  <li>The process never ends</li>
  </ul>
  
  <p>Can anyone explain how to start and stop this process as I wish?<br>
  I want this process to run every 5 minutes, but only once and when the app is open.</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {   
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      final Handler handler = new Handler();
      final Runnable r = new Runnable() {
          public void run() {
              // DO WORK
              Mantenimiento();
              // Call function.
              handler.postDelayed(this, 1000000);
          }
      };
      r.run();
  }
  </code></pre>