I am trying to prevent the activity from loading twice if I press the button twice instantly after the first click.
I have an activity which loads on click of a butt
// variable to track event time
private long mLastClickTime = 0;
2.In onClick check that if current time and last click time difference are less than i second then dont't do anything(return) else go for click event
@Override
public void onClick(View v) {
// Preventing multiple clicks, using threshold of 1 second
if (SystemClock.elapsedRealtime() - mLastClickTime < 1000) {
return;
}
mLastClickTime = SystemClock.elapsedRealtime();
// Handle button clicks
if (v == R.id.imageView2) {
// Do ur stuff.
}
else if (v == R.id.imageView2) {
// Do ur stuff.
}
}
}