I have an Android app which needs to play a sound resource on a timed interval, say every 120 seconds.
I know how to access the sound resources and play them, however it’s time timer part I’m not sure of. What’s the best approach?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I ended up ditching the
Timerapproach and used aHandlerinstead after stumbling upon an example at android-labs.So, instead of spawning the
TimerandTimerTaskin my Activity’sonCreate, I declared this privateHandlerwith in-lineRunnable:Also, I had to add code to my Activity’s
onResumeandonPause:This approach seems to work great.