How the Android program in JAVA Eclipse uses threads

Source: Internet
Author: User

We first define a Java class, the name can be arbitrary (for example, called the Clientheartbeat class, I am currently doing a socket communication client, we assume that a heartbeat can be tested), note that he will inherit the thread, Then reload the Run method (you must write the custom function you want in the overloaded Run method)

?

When we are going to use it, define an instance of the class and then execute the Start method, noting that the Start method is the Run method, but the two names do not change. Since the int type in the class is global, we can find that the output will continue to increase after multiple clicks

?

You can also test running two times, in fact, will be new two sub-threads, but they do things to increase the global variables, so the value will no longer be 1 seconds increments, but by two threads again function

?

Extend thread is only an implementation, sometimes not, for example, if we want to mainactivity also be able to implement threads, we can not inherit the thread, because the activity has been inherited (only inherit one)

?

How the Android program in JAVA Eclipse uses threads

Related Article

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.