title: code to be executed every x milliseconds, changeable
body: <p>I have a code to be executed every x milliseconds, where x is changeable during the app life cycle.</p>
  
  <p>Right now I use the postDelayed function of an handler, but I am not able to manage the situation when the delay changes.</p>
  
  <pre><code>handler.postDelayed(new Runnable() {
      @Override
      public void run() {
          // do some staff
  
          handler.postDelayed(this, x);
      }
  }, x);   
  </code></pre>
  
  <p>My problem is that in other parts of the app the <code>x</code> value can change, and I need to execute the code in the <code>run</code> function instantly after the change, and continue with the infinite execution of the delayed code (with new value of <code>x</code>).</p>