I have created a Service
in my android application which starts automatically on BOOT_COMPLETE
through BroadcastReceiver
. And That is
It is very simple.
steps:
1.create a Service class.
2.create a BroadcastReceiver class
3.call BroadReceiver in onDestroy method of service
4.In onReceive method of BroadReceiver class start service once again.
refer this link
According to Service documentation
The service will at this point continue running until Context.stopService() or stopSelf() is called.
So your service will run forever until system will not decide to kill it because of lack of resources.
According to documentation.
Reasons your service is killed:
The Android system stops a service only when memory is low and it must recover system resources for the activity that has user focus.
So as long as the above condition isn't met, your service will run forever.
Write your handler code in onStartCommand. But remember, your service will be paused when device goes in "sleep mode".