Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accelerometer sensor cause losses running into a service

I am developing an application for Android Wear. It listens coordinates from an accelerometer sensor and finds a pattern.

To do this, when the user clicks a button, the service starts and begins to store coordinates in a List. Usually, the accelerometer sensor logs 4 to 5 coordinates per second.

The problem is sometimes the onSensorChanged() method does not receive data during several seconds causing losses of data and trouble to find a pattern.

Here is a gist of my service: https://gist.github.com/cpalosrejano/8f0e59e47124275136fc3d5d941faa07

Things I've tried:

  • I am using android:stopWithTask=false to prevent the service to stop when the activity dies.
  • I have also used a WakeLock to prevent the device go to sleep while the services are recording coordinates.

What am I doing wrong? Is there another way to receive callbacks from the accelerometer sensor without causing data loss?

Thanks in advance.

like image 330
cpalosrejano Avatar asked Apr 03 '16 10:04

cpalosrejano


People also ask

What does accelerometer sensor do?

An accelerometer sensor is a tool that measures the acceleration of any body or object in its instantaneous rest frame. It is not a coordinate acceleration. Accelerometer sensors are used in many ways, such as in many electronic devices, smartphones, and wearable devices, etc.

What is the output of accelerometer sensor?

Accelerometers typically fall into two categories - producing either 10 mV/g or 100 mV/g. The frequency of the AC output voltage will match the frequency of the vibrations. The output level will be proportional to the amplitude of the vibrations.

How are accelerometers used in cars?

Accelerometers are likewise used in cars as the industry method way of detecting car crashes and deploying airbags almost instantaneously. In another example, a dynamic accelerometer measures gravitational pull to determine the angle at which a device is tilted with respect to the Earth.

What to do if accelerometer is not working?

Hold your device in your hand, wave it in the air in the pattern of a figure-eight a few times and then set the device back down on a flat surface. Accelerometer Sensor automatically re-adjusts the range of your accelerometer and can effectively calibrate your G-Sensor.


1 Answers

Its a bit late, but finnaly I found the solution.

I start the service in foreground, with method startForeground(int, Notification) so the service never wont stop. With this fix, you will never lost any SensorEvent.

like image 134
cpalosrejano Avatar answered Sep 28 '22 10:09

cpalosrejano