Summary of implementation methods of Android multithreading

Detailed examples of Android multithreading

Java multithreading mode

1. Inherit the thread thread and implement the run method

2. Implement runnable interface

Java single inheritance. When we want to put a subclass that has inherited other classes into thread, the limitation of single inheritance is reflected

However, multiple interfaces can be implemented, so the second method is much more flexible than the first

Secondly, through

The way to start a thread. If the variable is defined in runnable, multiple threads can share it because it comes from the same object

It is more suitable for multiple threads of the same program code to process the same resource

Android multithreading mode

It mainly focuses on the interaction between UI threads and other threads

1. Thread,Handler,Message 2. AsyncTask 3. Runnable

In the first way, new thread() is used to handle the corresponding processing through handler SendMessage, and the handler's handlemessage method is used to complete the interaction with the UI process

The second way is asynchronous thread, doInBackground () executes tasks, onPreExecute () prepares, onPostExecute () tasks are called after completion, onProgressUpdate and publishProgress are used together to achieve interaction with UI threads.

The third way is to use the runnable object to start the thread directly through the handler, post and other methods to realize the interaction with the UI thread

The above are the three methods of Android multithreading. If you have any questions, please leave a message or go to the community of this site for communication and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>