Hi again,

sorry to spam. I just found the following note in
http://developer.android.com/reference/android/hardware/SensorEventListener.html#onSensorChanged(android.hardware.SensorEvent)

NOTE: The application doesn't own the event object passed as a
parameter and therefore cannot hold on o it. The object may be part of
an internal pool and may be reused by the framework.

I don't know how I missed that, which explains the problem.

Thanks again for your help.

Regards,
Markus

On Oct 28, 10:38 pm, josean1968 <josean1...@gmail.com> wrote:
> Hello,
>
> You have this:
>
> ...
>     private SensorEvent lastEvent;
> ...
>
> @Override
>     public void onSensorChanged(SensorEvent event) {
>         if (lastEvent == null) {
>             lastEvent = event;
>             return;
>         }
>
>         Log.v(TAG, "dT [" + Thread.currentThread().getName() + "]: " +
> (event.timestamp - lastEvent.timestamp));
>     }
>
> ----------------
>
> The problem is that the "onSensorChanged()" method can be invoked
> concurrently because it is an event listener.
> Declare a local variable and copy the value (not just a pointer to the
> object):
>
> @Override
>     public void onSensorChanged(SensorEvent event) {
>       ...
>       int lastTimestamp = event.timestamp;
>       ...
>     }

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

Reply via email to