I want to run a foreground service forever that don't stop for any reason (whether the app process (activity) is killed, or whether the phone is in idle state (screen is off)). I have studied on internet and I come to know that android OS handles the background processes, and service is among one of those processes. So Android OS does not hesitate to kill any foreground service (because Android OS focuses on battery optimization and foreground service always consumes phone`s battery).
I come to know that if we want to run forever running process in background we can do this using foreground service and can start its notification using 'startForeground()'. I have tried to run foreground service, and also return START_REDELIVER_INTENT from 'onStartCommand()' so that my service should again start after destroying.
But if my phone goes to idle state then after sometimes (i.e. 5 minutes) my service automatically gets destroyed, and I don't know why my service did not start after destroying (even I used START_REDELIVER_INTENT).
Is there any way to make sure that our foreground service will always keep running in background?