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?
How to avoid multiple button click at same time in android?
How to Use Deprecated Handler() in Android - RRutors Guide
Open PDF in Google Drive with Intent in Android - RRutors
What is "shared preferences" in Android ?
How do I generate random numbers in Dart?
What is the Different Between val and var in Kotlin?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to get complete address from latitude and longitude?
What is ANR? How to avoid and resolve it?
Key Points to remember while develop the Android Application.
What is Android?
How to Exit android app on back pressed?
Android Studio project R can't find
What are the notifications available in android?
Explain Fragment Life Cycle
How to copy database from assets folder in android using kotlin
Fix Play Store Rejection Due to SMS Permission - RRutors
What is Intent? What is the difference between an implicit intent and an explicit intent?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Set Activity to Fullscreen Mode in Android - RRutors
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to get screen size (width,height) in Android?
What are Android Versions available?
Extract Date and Time from Long Type Variable - RRutors
How to Generate signed apk with android studio
How to convert milli seconds to hours, minutes and seconds in Android?
Check List for Generate Signed APK Android
What happens next when the device switches between portrait and landscape?
How to get an image resource by it's name in android?
What is Android Fragments?
How to check Android version?
How do i load image from drawable folder in Jetpack Compose?
Fix Android Emulator Kill Error When Running Your App
How To Set Text Color Programmatically Android TextView?
How can i comment inside xml file in android studio?
Invoke-customs are only supported starting with android 0 --min-api 26
Add Jar/Library Files as Dependency in Android Studio
How to start a new activity on button click
How do I check in SQLite whether a table exists?