0

I made an app which monitor incoming calls for some purpose. The app makes use of a service which in turn uses a PhoneStateListener to monitor incoming calls. My app requirement is for the incoming call monitoring behaviour to execute even when app is not running and screen is locked conditions.

The complexity starts when the phone screen is locked and the app is not running. I still need it to monitor incoming phone calls. For this, I decided to use a PARTIAL_WAKE_LOCK to keep the CPU running even when phone is locked.

App works in all cases after I did this, but using PARTIAL_WAKE_LOCK indefinitely like this is known to affect battery life.

I read somewhere that AlarmManager might be an alternative. But AlarmManager is used to trigger at specific time intervals, but I need the service to work when I get an incoming call, but that happens randomly.

What can I do to make the app more battery efficient without affecting functionality?

SoulRayder
  • 5,072
  • 6
  • 47
  • 93
  • 1
    Can you try http://stackoverflow.com/a/15564021/3209739 and instead of normal broadcast receiver use WakefulBroadcastReceiver. Follow http://stackoverflow.com/a/33923072/3209739 for detail on how to use wakeful. – cgr Jan 04 '16 at 17:43
  • @cgr : I have already got the call detection working, my only problem is potential battery drain. The wakefulbroadcast receiver is used to start and stop a service while holding the wakelock. But my problem is that I need the service to keep running in the background because incoming calls can occur anytime, regardless of phone state (screen-off,screen-on,reboot,app-running,app-not-running). Thereby, I would be holding the partial wake lock indefinitely. – SoulRayder Jan 04 '16 at 17:51

0 Answers0