1. Are you ready for the Galaxy S20? Here is everything we know so far!

How best to poll a sensor?

Discussion in 'Android Development' started by scorpicon, Dec 4, 2009.

  1. scorpicon

    scorpicon Newbie
    Thread Starter

    I'm writing at app that needs to update based on data coming from the orientation sensor. I was able to use the SensorEventListener's onSensorChanged method to continually get the data. However, I only want to poll for the data once every second.

    What is the best way to get the sensor data at a specific time interval?

    I'm coding for the 2.0 platform, so it'd be nice if any code samples used the current set of APIs. Thanks!
     



    1. Download the Forums for Android™ app!


      Download

       
  2. regulatre

    regulatre Newbie

    Use a timer:
    Timer (Java 2 Platform SE v1.4.2)

    Register a Java.util.Timer (above link) hat kicks off every 1 second and runs your sensor-checker-method().

    Or if you have a main loop, do stuff, sleep, check sensor, loop. I think Loops are discouraged in event-driven programming whenever possible.


     
  3. NilsT

    NilsT Lurker

    This feature should be built into the sensor service. Just like for the LocationManager where you can specify both an interval and a minimum change for the notification.
     
Loading...
Similar Threads - best poll sensor
  1. Ashok Rana
    Replies:
    0
    Views:
    213
  2. vivek_CVI
    Replies:
    10
    Views:
    338
  3. July Hoang
    Replies:
    6
    Views:
    390
  4. BBMIC
    Replies:
    1
    Views:
    236
  5. Neet4747
    Replies:
    3
    Views:
    282
  6. KerenSophia
    Replies:
    1
    Views:
    351
  7. GaryS1964
    Replies:
    5
    Views:
    815
  8. jasontech742
    Replies:
    1
    Views:
    966
  9. Antonio Salazar
    Replies:
    7
    Views:
    2,576
  10. Androidler123
    Replies:
    1
    Views:
    977

Share This Page

Loading...