SensorEventListener in separate thread

后端 未结 5 952
广开言路
广开言路 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:36

    Get the handler of the thread and register the listener on that thread. For example:

    public void run() {
        Sensor sensor = this.sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
        Looper.prepare();
        Handler gHandler = new Handler();
        this.sensorManager.registerListener(gravitySensorEventListener, sensor, SensorManager.SENSOR_DELAY_NORMAL, gHandler);
        Looper.loop();
    }
    

    hopes this would help you.

提交回复
热议问题