SensorEventListener in separate thread

后端 未结 5 942
广开言路
广开言路 2020-12-05 15:11

This seems like a basic question, but after searching for a while and playing with it, I\'ve come to the point where some help would be appreciated. I would like to have a

5条回答
  •  一生所求
    2020-12-05 15:34

    You can receive sensor event in a background thread. Instead of

    mSensorManager.registerListener(msl, mSensor, SensorManager.SENSOR_DELAY_UI );
    

    you can declare it with a handler referring to a secondary thread. The run loop of a thread looks like this:

    ...
    run {
        Looper.prepare;
        Handler handler = new Handler();
        ...
        mSensorManager.registerListener(msl, mSensor, SensorManager.SENSOR_DELAY_UI, handler );
        Looper.loop();
    }
    ...
    

提交回复
热议问题