K
K
kirawa2018-09-04 14:21:41
Android
kirawa, 2018-09-04 14:21:41

Is there an example of an unkillable service that will work constantly, in the background, until you turn it off on all versions of android?

It is necessary to develop a GPS Tracker. Help with a link to the git
There is some work, but from time to time the server stops

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2018-09-04
@402d

Two services mutually control that they are working, restart each other.
In the settings, require that there be a ban on stopping for energy saving.

D
Denis, 2018-09-04
@akaish

In Android, there is no guarantee that the service will not be terminated by the operating system for one reason or another. But no one prevents you from restarting the service if it stops. This is done as follows: In addition to the service, you can register a BroadcastReceiver that will restart your service when it is turned off. In the body of the onDestroy() method of your service, send your Broadcast, this Broadcast message will be received by the Broadcast receiver, upon receipt of which it will already restart your service.
It is also possible to check the health of the service from the outside with some frequency, using the AlarmManager, through which you can force the logic you define to be executed on a schedule.
The third way is to use the sticky service. When starting a service with START_STICKY, the OS must restart it when it stops.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question