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;
}
}
What is ANR in android?
Set Activity to Fullscreen Mode in Android - RRutors
Permission denied for window type 2010 in Marshmallow device
What is NetworkOnMainThread Exception?
What is Intent? What is the difference between an implicit intent and an explicit intent?
Extract Date and Time from Long Type Variable - RRutors
How to save activity State in Android?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How do i load image from drawable folder in Jetpack Compose?
How to get screen size (width,height) in Android?
What is the Different Between val and var in Kotlin?
How to get complete address from latitude and longitude?
How do I check in SQLite whether a table exists?
What happens next when the device switches between portrait and landscape?
How to copy database from assets folder in android using kotlin
How to validate email address in Android with Kotlin?
Decompile APK Files: How to Get Source Code - RRutors Guide
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Android Studio project R can't find
How to install/ uninstall apk by command line ADB
How to Use Deprecated Handler() in Android - RRutors Guide
How to avoid multiple button click at same time in android?
What is Android?
How to Exit android app on back pressed?
What is ANR? How to avoid and resolve it?
What is Context?
Open PDF in Google Drive with Intent in Android - RRutors
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What is Application?
Fix Android Emulator Kill Error When Running Your App
What is Android Fragments?
Invoke-customs are only supported starting with android 0 --min-api 26
How to find Android Device UDID or unique ID?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Fix Play Store Rejection Due to SMS Permission - RRutors
How to reduce APK package size?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to check Android version?
How do I generate random numbers in Dart?
Hide/Disable soft keyboard on Activity launch: Android