search

Home  >  Q&A  >  body text

android service中如何让主线程延迟一段时间再执行

在做一个蓝牙的程序,service启动之后,向连接的蓝牙设备发送消息,等收到返回的消息之后再执行主线程,应该怎么做啊。

伊谢尔伦伊谢尔伦2772 days ago588

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 14:28:06

    Is this a good experience? Why let the main thread wait? Usually time-consuming operations should not be done in the main thread. You all know 等收到返回的消息之后再执行主线程, why is it not easy to do it?
    1. Observer mode, listener.onReceive(Msg msg).
    2. Android has its own broadcast. When Bluetooth receives a message, it is OK to send a broadcast. The main thread receives the broadcast and processes it.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 14:28:06

    "After receiving the returned message" there should be a "notification" (callback method) to do the operation you want ~

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 14:28:06

    I am also currently working on a Bluetooth and smart bracelet app. Do you have an API for Bluetooth BLE operation?

    reply
    0
  • Cancelreply