Created
January 3, 2018 11:55
-
-
Save bastami82/ea0d984d5940df37490ff24fedf474c1 to your computer and use it in GitHub Desktop.
using Android handler as a timer to check a condition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Runnable runnable; | |
private Handler handler; | |
private boolean condition; | |
runnable = () -> { | |
if (condition) { | |
handler.removeCallbacks(runnable); //stop handler | |
} else { | |
handler.postDelayed(runnable, 500); //check a condition every half a second (until condition is met) | |
} | |
}; | |
handler.post(runnable); | |
/// some where in your code this conditin needs to get updated i.e condition = true; (other wise this check will go forever ;) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment