Search code examples
androidserviceandroid-servicepersistence

What is the difference between android:persistent vs Service.START_STICKY?


This blog clearly explained the difference between

  • Service.START_STICKY
  • Service.START_NOT_STICKY
  • Service.START_REDELIVER_INTENT

Now after reading this I got confused when seeing this service declaration with AndroidManifest.xml

<service android:name="com.amazon.tablet.myapplication.MyService" android:persistent="true"></service>

I assumed/understood so far that making android:persistent=true in service declaration would turn the service to persistent and restart when it goes down. But I'm able to achieve this without having persistent=true with Service.START_STICKY alone.

  1. What's the difference between android:persistent=true vs these attributes Service.START_STICKY, Service.START_REDELIVER_INTENT?
  2. When the service is recreated will the app be relaunched again? I'm trying to understand will the process for the application be created when the service recreated.

    Note : I declared the service with property android:persistent=true and tried killing my app with adb shell kill <pid> but it's recreated. I'm wondering / not understanding the difference between making the service recreation vs application recreation in this case.


Solution

  • 1. Service.START_STICKY

    This would wait for the intent to start the service (once the process associated with this gets killed)

    2. android:persistent="true"

    This would make the service as persistent true/false accordingly and this doesn't wait for the intent to make the service up again (once it gets killed due to LMK and all)

    3. Service vs Application persistent

    By making the service persistent this would make the process associated with it as persistent. And the same case with application.

    When you declare a separate process for your service then your app would not be persistent.