In the Android development process we often encounter such a problem, when the user clicks on a view to launch a new activity, if quickly multiple clicks will launch multiple identical interface. While it's very rare for users to play their own mobile phones, it's really a bad experience when it happens. Just before a period of time to study Lanchmode, then we have to start the acitivity to Singletop, so that the top can only have a same interface, the problem should be solved it? Experiment, can only say that the basic satisfaction requirements, but there are some special circumstances such as the use of Startactivityforresult start time is not good use. Let's solve this problem once and for all.
Home, in the project we want to create a parent class activity, called Fatheractivity Bar, practice has proved that the use of such a parent in the project is a lot of benefits ah, not listed here. Then you need to rewrite the Dispatchtouchevent method of the parent class, just a few lines of code. The idea is that every time there is a pressing event to do the interval of judgment, if it is a quick click on the direct interception down.
Click ( here) to collapse or open
- @Override
- public boolean dispatchtouchevent (Motionevent ev) {
- if (ev.getaction () = = Motionevent.action_down) {
- if (Util.isfastdoubleclick ()) {
- return true;
- }
- }
- return super.dispatchtouchevent (EV);
- }
For quick Click Judgment, we can define the desired event interval by ourselves, where I define a second:
Click ( here) to collapse or open
- public static Boolean Isfastdoubleclick () {
- Long time = System.currenttimemillis ();
- Long TimeD = Time-lastclicktime;
- Lastclicktime = time;
- return truetimed <= 1000;
- }
Finally, just let all the activity be inherited fatheractivity.
Troubleshoot multiple clicks on Android to start several identical interfaces