Android MessageQueue Mechanism

Android MessageQueue Mechanism

Core classes:

    Handler – the operator, user apps use this to operate the  Messages: send messagewith postRunnable, sendMessage etc. and process Messages in handleMessage.

   Message – the container for the data andinformation

   MessageQueue – the internal containers forMessages. User apps are not allowed to operate it directly. It is operatedinternally by Handler

   Looper – the rules which let thread rununtil stop() is called. This is much like use a while (true) in the thread tomake it run as long as you wish

   The general Message processing would be like this:

        1. make the thread (either main thread or user-created thread) can loop,with calling Looper.prepare();

        2. Send the Message with Handler.

        3. OverrideHandler.handleMessage to process the Message;

        4. Stop the looper by callingLooper.stop(), then thread will exit.


你可能感兴趣的:(thread,android,user,processing,containers)