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