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