Android: Which thread calls .onSensorChanged?

前端 未结 1 328
醉梦人生
醉梦人生 2021-01-02 16:33

I\'ve read a few discussions about which thread calls various callback methods, for example those associated with Sensors. Most claim that the UI thread calls the callbacks

相关标签:
1条回答
  • 2021-01-02 17:01

    Are we CERTAIN about that?

    Yes, though it depends on how you register the listener, and the behavior is not especially well-documented.

    There are two registerListener() methods that take a SensorEventListener. One takes a Handler, the other does not. The latter one will use a Handler that is associated with the main application thread. If you wish to have the events delivered to a background thread, use a HandlerThread (which really should be called LooperThread, but they didn't ask me...), create a Handler in it, and use that Handler with registerListener().

    0 讨论(0)
提交回复
热议问题