Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COThe one I've been playing with is >>public boolean registerListener (SensorEventListener listener, Sensor sensor, int rate)<<. Its docs say nothing about a Handler. Are you saying that the callback method is put into the queue as a Runnable object? Otherwise I don't see how the UI thread would understand how to call the callback function if a Message appeared on its Handler.
      singulars
    2. CO@AndroidNewbie: You are welcome to review the source code [for `SensorManager`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/hardware/SensorManager.java) and [the concrete implementation `SystemSensorManager`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/hardware/SystemSensorManager.java) at your leisure. Under the covers, Android currently creates one `Handler` per listener, using that `Handler` to dispatch events on the desired thread.
      singulars
    3. COThanks for the reference, I'll dig into it. When you say "on the DESIRED thread" (emphasis mine), does it compel that to be the UI thread? A Handler can be supported by non-UI threads too. This situation concerns me because it feels like there could be thread safety and synchronization problems if, despite everything being set up by a worker thread, the UI thread is then the one that invokes the callback. If that callback method is a member of some separate class, then you'll basically have two threads working within a common instance.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload