Android logoff, androidlogoff
I have already contributed to the use of Handler and Message for everyone. In this article, we will take a look at the specific use of Handler. This article mainly discusses the important role of logoff in processing Handler Message mechanisms, we know that we use the sendMessage () method to send messages to the main thread in the subthread, while the Handler processes messages through the handMessage () method, the internal message transmission mechanism, next we will discuss it together.
For your convenience, here is an example of daily life to introduce Handler and Looper's handling details: The example shows that we are going to the toilet during a meeting.
Looking at the example above, I think you must have a good understanding of logoff.
Handler objects implemented in the self-built Thread class:
Public class MainActivity extends Activity {private Handler firstHandler = new Handler () {public void handleMessage (android. OS. message msg) {System. out. println ("UI ------->:" + Thread. currentThread () ;};}; class Mythread extends Thread {private Handler handler; @ Override public void run () {loid. prepare (); // create a logoff Object handler = new Handler () {@ Override public void handleMessage (Message msg) {System. out. println ("sub-Thread:" + Thread. currentThread () ;}}; Looper. loop (); // loop processing method through this method}; private Mythread thread; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); thread = new Mythread (); thread. start (); try {Thread. sleep (3000);} catch (InterruptedException e) {e. printStackTrace ();} thread. handler. sendEmptyMessage (1); // process firstHandler in the Child thread. sendEmptyMessage (1); // process in the main thread} @ Override public boolean onCreateOptionsMenu (Menu menu) {getMenuInflater (). inflate (R. menu. main, menu); return true ;}}
LogCat information: