The app encountered this problem when the user clicked on a tag, using an asynchronous task to open a child thread to request data from the server and refresh the display.
But inevitably there are users like to play, and hard point, as programmers, we have to tolerate users. Therefore, we use the mechanism of delayed message, if the user clicks on the last click of the delay time, that the previous message has not been issued, and a message sent to handler, we can remove the previous message.
The code is as follows:
Handler1.removemessages (1000);
Handler1.sendemptymessagedelayed (1000, 500);
Executes the asynchronous task after the message is sent, so that the last task is not finished and a new task occurs. Obviously the last task is useless and needs to be canceled (if any).
Example code:
if (getcoursetask!= null &&!getcoursetask.iscancelled ()) {//Getcoursetask is an asynchronous task
Getcoursetask.cancel (TRUE);
Getcoursetask = null;
Pulltorefreshview.onrefreshcomplete ();//is the restoration work of the interface.
}
about how multiple asynchronous task threads cancel an issue with the previous thread