Created
November 4, 2017 13:33
-
-
Save alshell7/16d64d42d77e1f055e46f2ac5cc70f7b to your computer and use it in GitHub Desktop.
Preventing multiple executions of a method within a specified threshold time.
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 long mLastPostedTime = 0; | |
private final long threshold = 1000; //1 second | |
public void postExecution() | |
{ | |
if (SystemClock.elapsedRealtime() - mLastPostedTime < threshold) { | |
return; | |
} | |
mLastPostedTime = SystemClock.elapsedRealtime(); | |
// Your execution logic.. | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to import android.os.SystemClock;