Android is a simple way to interrupt and restart a thread thread

Here is a brief summary (general idea, no debugging, there may be mistakes!):

MyThread.java

There must be a while loop to judge the interrupt status in the run function. When the thread is interrupted externally, the call interrupt() must be displayed. Note: the interrupt() function only sets the interrupt flag instead of forcing an interrupt, so it is necessary to constantly detect the interrupt flag (thread. Interrupted()) in run

In Java, after interrupting the thread, you can't restart directly. You must create a new instance, or an error will be reported.

The above simple way for Android to interrupt and restart a thread thread is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>