android sound gets disabled after sometime

2019-08-28 21:05发布

问题:

i want to check how the service feature set in android works. to check it, i have a controller class that will start the service. in the service i have a handler that executes a function every minute.the function plays the sound. everything works well when the screen is on but after the screen goes dark(off), the sound is heard about 2-3 times (2-3 minutes) and then it stops... any idea why? and how can i make it (execute the sound function)work every minute?

回答1:

When the phone goes into sleep mode, so does the cpu. Some recievers may wake the phone up causing your sounds to be heard. Take a look into PowerManager and try to wake your phone(and cpu) up when you want to hear the sound.