How to check something at regular intervals?
<p>Beginner here, I have a simple question.</p>

<p>In Android what would be the best what to check for something at regular intervals?</p>

<p>Please bear with me, I'll try to explain the best I can --</p>

<p>For example my audio app is very simple, a main activity and a service. The main activity has a UI with two buttons, start and stop audio. I press start and the audio service starts. Likewise when I click Stop the service stops and the audio ends. If <code>isLooping()</code> is hard-coded to true there is no issue because the audio never ends unless I hit stop button, which stops the audio service and also resets the button states. </p>

<p>This is an issue now because I set <code>isLooping()</code> to false so the audio doesn't loop. So the audio will stop playing but the service is still running. </p>

<p>I want to be able to detect when the audio stops so I can set the states of the UI buttons. So I need something that is always checking whether audio is playing (i.e. check <code>player.isPlaying()</code> so I can end the service and set the enable/disable state of the buttons.</p>

<p>I figured out binding to the service so I can access the <code>MediaPlayer</code> controls via my main activity so I know the code to check if it's playing, but WHERE do I put this code so it's checked all the time? </p>

<p>Am I making sense? I know this is probably very simple. Thanks for any help.</p>
