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 bitmap from drawable: Android
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What is Android Fragments?
What happens next when the device switches between portrait and landscape?
Extract Date and Time from Long Type Variable - RRutors
How to save activity State in Android?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to avoid multiple button click at same time in android?
Add Jar/Library Files as Dependency in Android Studio
How to get screen size (width,height) in Android?
Invoke-customs are only supported starting with android 0 --min-api 26
What is Context?
What is Application?
How to Exit android app on back pressed?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How can i comment inside xml file in android studio?
Hide/Disable soft keyboard on Activity launch: Android
How to reduce APK package size?
How to Generate signed apk with android studio
What is the difference between match_parent and fill_parent?
What is ANR in android?
What are Android Versions available?
How to convert DP to Pixel and Pixel to Dp?
Key Points to remember while develop the Android Application.
How to Use Deprecated Handler() in Android - RRutors Guide
What is ANR? How to avoid and resolve it?
How to stop EditText focus at Activity startup in Android?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How do i load image from drawable folder in Jetpack Compose?
Android Studio project R can't find
Explain Fragment Life Cycle
What is NetworkOnMainThread Exception?
How do I check in SQLite whether a table exists?
Fix Play Store Rejection Due to SMS Permission - RRutors
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to copy database from assets folder in android using kotlin
How to get an image resource by it's name in android?
Fix Android Emulator Kill Error When Running Your App
What is the Different Between val and var in Kotlin?