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; @Override
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
public void onClick(View v) {
// Preventing multiple clicks, using threshold of 1 second
if (SystemClock.elapsedRealtime() - lastPressesTime < 1000) {
return;
}
lastPressesTime = SystemClock.elapsedRealtime();
switch(v.getId())
{
case R.id.widget1:
break;
case R.id.widget2:
break;
}
}
How to get screen size (width,height) in Android?
How to Get bitmap from drawable: Android
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
What is Android Fragments?
Fix Android Emulator Kill Error When Running Your App
What are Android Versions available?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to reduce APK package size?
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to get an image resource by it's name in android?
What is the Different Between val and var in Kotlin?
What is the difference between match_parent and fill_parent?
What happens next when the device switches between portrait and landscape?
How do I generate random numbers in Dart?
What is ANR in android?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Hide/Disable soft keyboard on Activity launch: Android
How to Generate signed apk with android studio
How To Set Text Color Programmatically Android TextView?
How to Use Deprecated Handler() in Android - RRutors Guide
Check List for Generate Signed APK Android
What is Application?
How do I check in SQLite whether a table exists?
How to validate email address in Android with Kotlin?
What is NetworkOnMainThread Exception?
FCM Not Receiving Notifications in Android - RRutors
How to find Android Device UDID or unique ID?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Decompile APK Files: How to Get Source Code - RRutors Guide
Explain Fragment Life Cycle
How to start a new activity on button click
How to copy database from assets folder in android using kotlin
Extract Date and Time from Long Type Variable - RRutors
How to Exit android app on back pressed?
Open PDF in Google Drive with Intent in Android - RRutors
How to avoid multiple button click at same time in android?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to get a contact image using a phone number in android?
How can i comment inside xml file in android studio?