Corrected two consecutive buttons for android Processing

Source: Internet
Author: User

1. Variable initialization:


Private boolean isExit = false;
Private boolean hasTask = false;
Private boolean isExit = false;
Private boolean hasTask = false; 2. Key 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 );
}
}
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;
}
}
Public class PressHomeKeyCount extends Handler {
Public void handleMessage (final Message msg ){
IsExit = false;
HasTask = true;
}
}


The above practice will show an endless loop, and I have improved it. The following is the improved code. After testing, there is no problem. 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;
}
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;
}
}

From the column xiaoxiaobian3310903

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.