Handler is an interface provided by Android for inter-thread communication.
I didn't pay attention to it at first, because handler is used by the main thread, that is, the UI thread, and the main thread has a message loop by default.ProgramIs transparent.
Therefore, I mistakenly thought that handler is useless like a Linux signal.
Linux signal processing programs are very limited. We recommend that you set a flag in the processing program and process it in other loops.
Even using printf in a processing program may lead to a deadlock in a single-threaded program!
For Android, if a non-UI thread uses handler to receive messages, it must explicitly call loop. Prepare ();
To process messages, you need to provide your own loop. Loop (); this is not the SB design like the Linux signal! This is in line with human thinking!
Supplement
Logoff made me so disappointed. The loop () method is an endless loop. Users cannot know when and under what conditions to exit the loop.
I don't know when to call this quit () method, because I don't know whether the message queue has been processed.
In the game loop is not available, so you have to implement a queue of 1v1 on your own. Fortunately, the operation is completely normal.
If logoff can provide interfaces such as Win's peekmessage, it is better to hand over the loop to the user's own writing, with more control room.
It seems that the idlehandler is provided, and the callback is empty for the message queue. If you have time, replace it. You can use the one you have written.