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;
}
}
Explain Fragment Life Cycle
What is "shared preferences" in Android ?
How to find Android Device UDID or unique ID?
Key Points to remember while develop the Android Application.
Android Studio project R can't find
How to get screen size (width,height) in Android?
What is the Different Between val and var in Kotlin?
How to reduce APK package size?
Extract Date and Time from Long Type Variable - RRutors
How to Exit android app on back pressed?
Open PDF in Google Drive with Intent in Android - RRutors
What is Android Fragments?
How to check Android version?
How to install/ uninstall apk by command line ADB
What is Intent? What is the difference between an implicit intent and an explicit intent?
What is Application?
How to get complete address from latitude and longitude?
What are Android Versions available?
How to get an image resource by it's name in android?
How to Generate signed apk with android studio
Set Activity to Fullscreen Mode in Android - RRutors
Decompile APK Files: How to Get Source Code - RRutors Guide
How do i load image from drawable folder in Jetpack Compose?
FCM Not Receiving Notifications in Android - RRutors
What is ANR? How to avoid and resolve it?
What is ANR in android?
How can i comment inside xml file in android studio?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to avoid multiple button click at same time in android?
How to validate email address in Android with Kotlin?
What is Context?
What are the notifications available in android?
How to stop EditText focus at Activity startup in Android?
Invoke-customs are only supported starting with android 0 --min-api 26
How to Use Deprecated Handler() in Android - RRutors Guide
How to copy database from assets folder in android using kotlin
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What is the difference between match_parent and fill_parent?
What is NetworkOnMainThread Exception?
ERR_ACCESS_DENIED in Android Webview with sdk 30