Search code examples
androidserviceonstart

Restarting Services in Android


In android application if I save the intent of the service that is running. How can I restart the service? I want it to run onStartCommand function again.

Thanks


Solution

  • Make onStartCommand return START_STICKY .

    public int onStartCommand(Intent intent, int flags, int startId){
       super.onStartCommand(intent, flags, startId);
       return  START_STICKY; 
    }
    

    Documentation link: http://developer.android.com/reference/android/app/Service.html