How to avoid multiple button click at same time in android?

Some times user may clicks multiple times on same widget, at that time App misleads and gives crassh/un expected behaviour to user.
We can resolve this by using the below code

The standard way to avoid multiple clicks is to save the last clicked time and avoid the other widget clicks within a preferred time


private long lastPressesTime;

public void onClick(View v) {
    // Preventing multiple clicks, using threshold of 1 second
    if (SystemClock.elapsedRealtime() - lastPressesTime < 1000) {
    lastPressesTime = SystemClock.elapsedRealtime();


Flutter Questions

Android Questions

Python Questions

Java Questions