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;
}
}
Fix Play Store Rejection Due to SMS Permission - RRutors
Permission denied for window type 2010 in Marshmallow device
Extract Date and Time from Long Type Variable - RRutors
FCM Not Receiving Notifications in Android - RRutors
What is ANR in android?
How to start a new activity on button click
How to save activity State in Android?
How to get screen size (width,height) in Android?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to find Android Device UDID or unique ID?
Decompile APK Files: How to Get Source Code - RRutors Guide
What is Application?
How to stop EditText focus at Activity startup in Android?
Open PDF in Google Drive with Intent in Android - RRutors
How do I check in SQLite whether a table exists?
How to validate email address in Android with Kotlin?
Add Jar/Library Files as Dependency in Android Studio
What are Android Versions available?
Set Activity to Fullscreen Mode in Android - RRutors
Fix Android Emulator Kill Error When Running Your App
How to get complete address from latitude and longitude?
What is "shared preferences" in Android ?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
What is ANR? How to avoid and resolve it?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What is Context?
How to Use Deprecated Handler() in Android - RRutors Guide
Fix Duplicate Files in APK Build.gradle Issue - RRutors
How to Generate signed apk with android studio
What is the difference between match_parent and fill_parent?
How to Exit android app on back pressed?
Invoke-customs are only supported starting with android 0 --min-api 26
What is NetworkOnMainThread Exception?
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to convert milli seconds to hours, minutes and seconds in Android?
What is the Different Between val and var in Kotlin?
What are the notifications available in android?
What happens next when the device switches between portrait and landscape?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to Get bitmap from drawable: Android