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 NetworkOnMainThread Exception?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to start a new activity on button click
How to convert milli seconds to hours, minutes and seconds in Android?
Fix Play Store Rejection Due to SMS Permission - RRutors
What is Android Fragments?
How to Generate signed apk with android studio
FCM Not Receiving Notifications in Android - RRutors
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How do I generate random numbers in Dart?
How to Get bitmap from drawable: Android
How to find Android Device UDID or unique ID?
How to get an image resource by it's name in android?
How to convert DP to Pixel and Pixel to Dp?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What are Android Versions available?
How to check Android version?
What is "shared preferences" in Android ?
How to copy database from assets folder in android using kotlin
Invoke-customs are only supported starting with android 0 --min-api 26
How to Exit android app on back pressed?
Set Activity to Fullscreen Mode in Android - RRutors
What is ANR? How to avoid and resolve it?
Check List for Generate Signed APK Android
What is the difference between match_parent and fill_parent?
How to validate email address in Android with Kotlin?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What happens next when the device switches between portrait and landscape?
What is Context?
How to stop EditText focus at Activity startup in Android?
Add Jar/Library Files as Dependency in Android Studio
How to reduce APK package size?
Extract Date and Time from Long Type Variable - RRutors
Explain Fragment Life Cycle
How to get complete address from latitude and longitude?
Open PDF in Google Drive with Intent in Android - RRutors
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Fix Android Emulator Kill Error When Running Your App
How to get a contact image using a phone number in android?
How to install/ uninstall apk by command line ADB