Acclerometer Sensor in Separate Thread

后端 未结 1 1228
一整个雨季
一整个雨季 2020-12-03 09:34

I am saving data from Accelerometer Sensor to Database, but I want to do it in a separate thread. I tried to search it on Internet but most of them uses the same thread.

相关标签:
1条回答
  • 2020-12-03 09:55

    First you need to use registerListener(SensorEventListener listener, Sensor sensor, int rate, Handler handler) and supply a Handler that is running on a background thread.

    Create a HandlerThread, get its Looper, create a Handler supplying the looper.

    This will let you receive the callbacks on the background thread. When finished ensure you remove the listener and then call Looper.quit(), to exit the thread.

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