Jodes Jodes - 19 days ago 11
Android Question

SensorManager.registerListener (.., Handler handler), example please?

I don't understand how to use this method,

sensorManager.registerListener(SensorEventListener listener, Sensor sensor, int rate, Handler handler);

(Documentation here)

1) If it uses a SensorEventListener, then what's the purpose of the Handler?

2) Please give an example of a handler I could pass to it?

Thanks!

Answer

If it uses a SensorEventListener, then what's the purpose of the Handler?

If I had to guess, it is so you can get your sensor events delivered on a background thread (e.g., a HandlerThread). By default, sensor events are delivered on the main application thread, which is fine in some cases.

Comments