The simplest way is just to remember, something like this:
boolean lastWasElse = false;
mHandler.post(new Runnable() {
@Override
public void run() {
if(true) {
// do this
lastWasElse = false;
} else if (!lastWasElse) {
// do once and then loop again, but if the answer is still "else" then skip this line.
lastWasElse = true;
}
}
The trouble is where you store the lastWasElse variable - since you are constantly creating new runnables. You need to store one copy of that variable somewhere centrally and check it each time the task runs...
...or re-use the same Runnable
constantly instead of creating new ones and store the variable inside the Runnable
.