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;
}
}
Open PDF in Google Drive with Intent in Android - RRutors
What is the difference between match_parent and fill_parent?
Explain Fragment Life Cycle
What are the notifications available in android?
Permission denied for window type 2010 in Marshmallow device
Key Points to remember while develop the Android Application.
What is "shared preferences" in Android ?
How to get a contact image using a phone number in android?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What happens next when the device switches between portrait and landscape?
What is ANR in android?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Fix Play Store Rejection Due to SMS Permission - RRutors
How to find Android Device UDID or unique ID?
How do i load image from drawable folder in Jetpack Compose?
How to stop EditText focus at Activity startup in Android?
How to save activity State in Android?
FCM Not Receiving Notifications in Android - RRutors
How to validate email address in Android with Kotlin?
What are Android Versions available?
What is NetworkOnMainThread Exception?
How to convert DP to Pixel and Pixel to Dp?
What is ANR? How to avoid and resolve it?
What is Context?
How do I check in SQLite whether a table exists?
How to check Android version?
Fix Android Emulator Kill Error When Running Your App
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Invoke-customs are only supported starting with android 0 --min-api 26
How to get complete address from latitude and longitude?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How To Set Text Color Programmatically Android TextView?
How to Generate signed apk with android studio
What is Android?
How to reduce APK package size?
How do I generate random numbers in Dart?
How to convert milli seconds to hours, minutes and seconds in Android?
Add Jar/Library Files as Dependency in Android Studio
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to Exit android app on back pressed?