I have a service which sends a notification when the user changes his/her location. This service is working fine, but the problem arises when the user closes the app as the
There are two kinds of Android Services: started and bound. You need to use the first one(started Service). The documentation shows how to use it, there is a nice lifecycle diagram below.
Instead of starting and binding the service in one step using bindService()
you need to call startService()
first. However startService()
won't help you starting from Oreo. You need to usestartForegroundService()
from there. Then it runs until you stop it, even if the app is closed.
Start Sticky Service
if you want Android OS
to pick your service again if it killed it.