How to let sensors periodically work?
<p>I am currently developing an app in Android which will record sensor data for a fixed length of time for several cycles. For example, I plan to record the data for 10 seconds, and then stop, let the phone rest for 10 seconds, and start record again, ... working in this pattern for 1 hour. My question is, how to let the phone automatically execute this plan?  I am currently using code below ( from <a href="http://stackoverflow.com/questions/10119297/android-how-to-collect-sensor-values-for-a-fixed-period-of-time">Android: How to collect sensor values for a fixed period of time?</a>) , but it only works for one cycle, I have to manually start new cycles after I am sure the previous cycle has finished.</p>

<pre><code>public void onResume() {
mSensorManager.registerListener(mListener, mSensorAcceleration, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(mListener, mSensorMagnetic, SensorManager.SENSOR_DELAY_GAME);
Handler h = new Handler();
h.postDelayed(new Runnable() {

    @Override
    public void run() {
    //    do stuff with sensor values
        mSensorManager.unregisterListener(mListener);               
    }
}, 10000);
</code></pre>

<p>...</p>

<p>Any help will be appreciated!!</p>
