On Sun, Jan 22, 2012 at 8:14 AM, ambi <[email protected]> wrote:
> Thanks Mark. I understand that SensorEventListener.onSensorChanged()
> is the only way right now to read the value of sensor. But why is it
> that way?

Because that's the way they wrote it.

> I mean isn't there a need for a method that can give the
> sensor value at some instant rather than when the value changes?

You assume that is technically possible. Most sensors are not powered
on constantly, to minimize battery drain. AFAIK there is no guarantee
that a sensor can turn on in a matter of milliseconds. Hence, a
getMeMySensorReadingNowDammit() method might block for a period of
time, and Android tries to avoid such blocking calls where it can.
This is much the same rationale as why there is no
whereTheHeckAreWeRightNow() method on LocationManager, because,
depending upon the chosen location provider, it may take some time to
come up with an answer to the question.

If you want a single reading, simply register a SensorEventListener,
and in the listener itself, unregister once you get your first
reading. SensorManager *could* be augmented to provide some helper
code around that, akin to LocationManager's requestSingleUpdate(), but
it would still be asynchronous.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Warescription: Three Android Books, Plus Updates, One Low Price!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to