Android: Disable Multi Tapping

Disable multi tapping. So you have developed a very nice Android application, user taps a Button or Image on application and it shows another screen or do some action. Have you ever thought if user does not have patience for few hundred milliseconds or device is a bit slow due to all free applications installed from Android Market and in anticipation user kept taping until new screen doesn’t show up then what will happen? Yes the process against click will run as many times as number of taps.

Surely you won’t be willing to start another process while current process haven’t completed yet. Here are couple of tips to disable double tapping.

Enable/Disable All Clicks:

Make two functions in Class. 1st to disable onClick event on all clickable Buttons/Images using variableName.setEnabled(false) and 2nd to enbable onClick event for all clickable Buttons/Images using variableName.setEnabled(true). Call disable function as soon as user taps 1st time and call enable function after completion of that process or after showing screen or some dialogue.

[NOTE: This is Highly Recommended.]

Make Single View Object:

I will not dig down to android best practices but just to let you know that it is recommended to make separate classes for each screen and manage show(), hide() functions for better usage of views and dialogues. On Button/Image Click rather than creating new Object of Class every time all you need is to do is to define reference of it at Class Level in Class that is handling onClick event. Just put a null check where actually new Object is required to be initiated so the Object of new screen Class will be generated only once. Now implement hide() and show() methods in called class, use show() method to display and on closure of that screen just hide it using hide().

[NOTE: Hiding will keep the object alive in memory and it is not recommended.]

These are not only few solutions to the problem. There could be many more.