0

I have tried using START_STICKY on the onStartCommand() method of intent services, I have even tried changing the process name of the service on the manifest.xml file. But none works. Whenever I kill the app, the service also gets destroyed. I want to design a service that gets triggered when the user starts the app for the first time and then keeps on running even after user kills the application. Any help will be useful

João Fernandes
  • 491
  • 7
  • 17

2 Answers2

2

In service class implement on destroy method which will trigger a broadcast. In that broadcast receiver class implement on receive method. So whenever service destroyed this broadcast receiver class will execute onreceive method. In that onreceive method start the service again.

Shaik Salam
  • 51
  • 1
  • 11
1

Your service must be in the foreground to prevent the system from closing it. See the startForeground method in the Service class.

Zelig63
  • 1,592
  • 1
  • 23
  • 40