android - handler的sendMessage()和handleMessage()能不能都在主线程,如果可以,那这样做有必要么?
高洛峰
高洛峰 2017-04-17 17:16:30
0
11
1696
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(11)
刘奇

Handler is mainly used for asynchronous message processing.
If it is all on the main thread, I personally think it is not necessary

洪涛

This is definitely possible, but whether it is necessary depends on personal habits.

阿神

It can all be in the main thread. It can be used when doing some linkage. It may also be used when customizing controls

刘奇
  1. Yes.

  2. You can only tell whether it is necessary based on the business. I have to say it’s not necessary, you must write a big news article to criticize me

伊谢尔伦

The answer is yes, many simple demos for teaching are written like this, but it is generally not done in projects

Peter_Zhu

Handler is used for inter-thread communication, of course there is no problem between the main thread and the main thread

However, I personally feel that Handler is too manual, cumbersome, and has many restrictions to use. If you need to perform tasks in a new thread and publish them to the main thread, why not try AsyncTask or RxAndroid?

In addition, it is the main thread, why not call the method directly?

刘奇

If you need to control the rhythm of UI updates, you can use this logic

伊谢尔伦

This is for sure
Is it necessary to look at your specific needs?

洪涛

It is definitely possible. It mainly depends on the demand. It is usually done in the main thread

洪涛

If Looper is not specified, it defaults to the main thread. If the processing is not time-consuming, it doesn't matter if it's all on the main thread.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template