Service restarts when activity is killed

I have an activity that starts a service in a separate process using the android:process attributes of my service.

The onStartCommand() service function returns START_STICkY .

I kill my activity process by scrolling it using the button of the latest applications, and the service process will restart.

I want to know if there is a way for the service to work when the activity process has been killed.

+4
source share
1 answer
 I want to know if there is a way to keep the service running when the activity process is killed. 

No, there is no way to save the service. Because

 Closed by the user via the Running Services screen in Settings. Closed by the user via a task killer. Closed by Android to free up memory in times of need. 

Continue the BAD service.

But you can do

-> you can restart the service using the BROADCAST RECEIVER . (for an incoming call, termination of BOOT, received SMS, etc., use this depending on your requirement)

0
source

Source: https://habr.com/ru/post/1480042/


All Articles