0

I've a problem with my android application. I'm using a background service (with notification on the status bar) which performs an audio sample every hour. To perform this sample I generate a broadcast event every hour and when I capture the event the audio recording starts. During the day, when I'm using the phone, I've no problems. The strange behavior happens during night, when it seems like if the phone goes to an "idle" state: the broadcast events are no more processed. From the log file I understood that the events are generated and putted in a queue... and when I start using again the phone, all those events are raised in the same moment. Do u have any idea about how to solve this problem? How can I force the phone to continue processing my events? do I have to set any variable of flag to avoid the phone going in this kind of "idle" state? hope someone can help me!

thank you in advance! michela

1 Answers1

0

I'm using a background service (with notification on the status bar) which performs an audio sample every hour.

Why not use AlarmManager, so you do not take up as much memory? Users really do not like everlasting services.

The strange behavior happens during night, when it seems like if the phone goes to an "idle" state: the broadcast events are no more processed.

Of course.

Do u have any idea about how to solve this problem?

Use AlarmManager and a WakefulIntentService. Schedule the AlarmManager to invoke your application every hour (ideally via setInexactRepeating()). Have the WakefulIntentService obtain your sample. If you follow the documented WakefulIntentService recipe, the device will stay awake long enough for you to get your sample, then will fall back asleep. Your service will not remain in memory all of the time. You get your functionality, and the user gets better device performance.

Do NOT just use a WakeLock so your application not only eats up memory all of the time, but keeps the CPU running all of the time.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491