Skip to content

Instantly share code, notes, and snippets.

Created Aug 3, 2015
What would you like to do?
how to invoke the same method in a loop
public class Loop {
private static boolean isStarted = false;
private static Handler handler = new Handler();
private static ConcreteActivity activity;
public static boolean isActive = true;
private static Runnable stepTimer = new Runnable() {
public void run() {
if (isActive) {
handler.postDelayed(this, 2000); //LoopAction() is invoked every 2 seconds
public static void start(ConcreteActivity view) {
if (!isStarted) {
handler.postDelayed(stepTimer, 1000); //start looping after 1 second of delay
isStarted = true;
activity = view;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment