search

Home  >  Q&A  >  body text

android - handler的sendMessage()和handleMessage()能不能都在主线程,如果可以,那这样做有必要么?

高洛峰高洛峰2772 days ago1702

reply all(11)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:18:30

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:18:30

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

    reply
    0
  • 阿神

    阿神2017-04-17 17:18:30

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

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:18:30

    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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:18:30

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

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:18:30

    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?

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:18:30

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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:18:30

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:18:30

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:18:30

    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.

    reply
    0
  • Cancelreply