The service can run in the background indefinitely , even if the component that started it is destroyed. As such, the service should stop itself when its job is complete by calling stopSelf() , or another component can stop it by calling stopService() .
Read moreHow do I start background services on Android?
Start android studio and right-click the package name in the android studio left project panel. Click the menu item New —> Service —> Service. Give the android background service a name by input its name in the next New Android Component window Class Name input box, check both the Exported and Enabled checkbox.
Read more