Android logoff, androidlogoff

Source: Internet
Author: User

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:

  

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.