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 Android Fragments?
Extract Date and Time from Long Type Variable - RRutors
Open PDF in Google Drive with Intent in Android - RRutors
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Permission denied for window type 2010 in Marshmallow device
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
What are Android Versions available?
How to save activity State in Android?
What is the difference between match_parent and fill_parent?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Fix Play Store Rejection Due to SMS Permission - RRutors
What is ANR in android?
How To Set Text Color Programmatically Android TextView?
How to stop EditText focus at Activity startup in Android?
How to reduce APK package size?
How to install/ uninstall apk by command line ADB
ERR_ACCESS_DENIED in Android Webview with sdk 30
Decompile APK Files: How to Get Source Code - RRutors Guide
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Set Activity to Fullscreen Mode in Android - RRutors
Add Jar/Library Files as Dependency in Android Studio
How to get screen size (width,height) in Android?
What is "shared preferences" in Android ?
What is the Different Between val and var in Kotlin?
How to convert DP to Pixel and Pixel to Dp?
How do I generate random numbers in Dart?
How to start a new activity on button click
FCM Not Receiving Notifications in Android - RRutors
Explain Fragment Life Cycle
Check List for Generate Signed APK Android
How to convert milli seconds to hours, minutes and seconds in Android?
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to Generate signed apk with android studio
How can i comment inside xml file in android studio?
How to Use Deprecated Handler() in Android - RRutors Guide
How to get a contact image using a phone number in android?
Key Points to remember while develop the Android Application.
What happens next when the device switches between portrait and landscape?
How do I check in SQLite whether a table exists?
What is Android?