How To Restart The Service Automatically In Android?
I have started a service in Activity.Now, if i force close the activity then automatically the service is also force stopped.Is there any way to restart it automatically.? Thanks i
Solution 1:
You must implement the onStartCommand()
method by returning the START_STICKY
or START_REDILIVER_INTENT
, but it's your responsibility to stop the service by calling stopService()
or stopSelf()
method.
Solution 2:
You should return START_STICKY from onStartCommand in your service. This will make sure Android restarts your service after being killed. See the link bellow.
http://developer.android.com/reference/android/app/Service.html#START_STICKY
This will not deliver again the original intent. If you also need that return START_REDELIVER_INTENT.
These are also explained in the Android blog.
http://android-developers.blogspot.com.au/2010/02/service-api-changes-starting-with.html
Post a Comment for "How To Restart The Service Automatically In Android?"