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 find Android Device UDID or unique ID?
FCM Not Receiving Notifications in Android - RRutors
What is Application?
Check List for Generate Signed APK Android
How to Get bitmap from drawable: Android
How to reduce APK package size?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Invoke-customs are only supported starting with android 0 --min-api 26
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
What is the Different Between val and var in Kotlin?
Set Activity to Fullscreen Mode in Android - RRutors
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How To Set Text Color Programmatically Android TextView?
What is ANR? How to avoid and resolve it?
What are Android Versions available?
How do I check in SQLite whether a table exists?
What is the difference between match_parent and fill_parent?
Open PDF in Google Drive with Intent in Android - RRutors
How to stop EditText focus at Activity startup in Android?
How to get a contact image using a phone number in android?
Key Points to remember while develop the Android Application.
Add Jar/Library Files as Dependency in Android Studio
How to copy database from assets folder in android using kotlin
How to Exit android app on back pressed?
Extract Date and Time from Long Type Variable - RRutors
How to get complete address from latitude and longitude?
Android Studio project R can't find
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
What is NetworkOnMainThread Exception?
What is Android?
How to get an image resource by it's name in android?
How do I generate random numbers in Dart?
How to convert milli seconds to hours, minutes and seconds in Android?
How to convert DP to Pixel and Pixel to Dp?
How do i load image from drawable folder in Jetpack Compose?
How to Use Deprecated Handler() in Android - RRutors Guide
What happens next when the device switches between portrait and landscape?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to start a new activity on button click