Corrected two consecutive buttons for Android Processing

Source: Internet
Author: User

1. Variable initialization:

 
Private Boolean isexit = false; private Boolean hastask = false;

2. Button capture (for example, in the ontouchdown function for button listening)

 
Presshomekeycount localhandler = new presshomekeycount (); If (isexit = false) {isexit = true; If (! Hastask) {message localmessage = new message (); localmessage. what = 0; localhandler. sendemptymessagedelayed (localmessage. what, 500l);} else {If (mrecentapplication. getvisibility () = view. visible) {mrecentapplication. setvisibility (view. invisible); isexit = false; hastask = false ;}} else {If (mrecentapplication. getvisibility () = view. invisible) {mrecentapplication. setvisibility (view. visible );}}

3. Handle object

Public class presshomekeycount extends handler {public void handlemessage (final message MSG) {isexit = false; hastask = true ;}}

The above practice will have an endless loop, and I have improved it. The following is the improvedCode, There is no problem after testing, where the variable Initialization is the same

2. Key capture

If (isexit = false) {isexit = true; If (! Hastask) {message localmessage = new message (); localmessage. what = 0; localhandler. sendemptymessagedelayed (localmessage. what, 500l);} else {isexit = false; hastask = false; localhandler. removemessages (0); If (mrecentapplication. getvisibility () = view. visible) {mrecentapplication. setvisibility (view. invisible) ;}} else {If (mrecentapplication. getvisibility () = view. invisible) {mrecentapplication. setvisibility (view. visible);} localhandler. removemessages (0); isexit = false; hastask = true ;}

 
 

3. Handler object

Public class presshomekeycount extends handler {public void handlemessage (final message MSG) {isexit = false; hastask = false ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.