Last active
May 4, 2018 05:07
-
-
Save aruke/c66563d13f16dca093b8 to your computer and use it in GitHub Desktop.
This file contains 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
// Call this method directly from java file | |
int secs = 2; // Delay in seconds | |
Utils.delay(secs, new Utils.DelayCallback() { | |
@Override | |
public void afterDelay() { | |
// Do something after delay | |
} | |
}); |
This file contains 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
import android.os.Handler; | |
public class Utils { | |
// Delay mechanism | |
public interface DelayCallback{ | |
void afterDelay(); | |
} | |
public static void delay(int secs, final DelayCallback delayCallback){ | |
Handler handler = new Handler(); | |
handler.postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
delayCallback.afterDelay(); | |
} | |
}, secs * 1000); // afterDelay will be executed after (secs*1000) milliseconds. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment