I want to run a repetitive task which do some background task, it do not need to show its progress or any UI update. but it must run even app goes swiped with minimum resource usage.(battery, CPU, etc etc), please suggest me some way. how to do that.
This background task must be start from application and stooped from application only.
My Main Problem:
App has two State:1. Start App 2.Stop App
in "Start App State" i need to check whether location service is enable or not, even app swiped, so i write Service and Timer in it to check repetitively that Location Service is enable.
in "Stop App State" i need to stop the timer and stop the service.
now Problem is that Timer is not running sometime, so it do not set flag in preferences.
List of Solution i had tried:
BroadCastReciever with "PROVIDERS_CHANGED_ACTION" event Listened, but it do not call receiver everytime when user start-stop the location service,
so i write Service with Timer to check location service is enable or disable. but Timer do not run everytime, as i checked in two device(Samsung S5 & Google Nexus 6).
so i remove service and i use AlaramManager with BroadcastReciever it can run as Expected but i need to take care about device Resources(Bettry and CPU) becuase it will execute every 1 sec.
so Advice me.
Thanks in advance