Skip to content

Instantly share code, notes, and snippets.

@alshell7
Created November 4, 2017 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alshell7/16d64d42d77e1f055e46f2ac5cc70f7b to your computer and use it in GitHub Desktop.
Save alshell7/16d64d42d77e1f055e46f2ac5cc70f7b to your computer and use it in GitHub Desktop.
Preventing multiple executions of a method within a specified threshold time.
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..
// ...
}
@alshell7
Copy link
Author

alshell7 commented Nov 4, 2017

Need to import android.os.SystemClock;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment