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?