Question

I am having some trouble manually ending the IntentService onHandleIntent method. I am catching an exception which is crucial to the execution of the rest of the thread and I want to stop the thread as i catch the exception. I tried calling stopSelf() or directly calling onDestroy() which I'm sure are probably very bad ways of doing it, and they aren't working. The thread calls them and then continues.

Anyone have any good ideas of how to do this?

Était-ce utile?

La solution

As sonykuba said, finishing the onHandleIntent method stops the Service. So you could do something like this:

public void onHandleIntent {
  try {
   // ... your code here
  } catch(YourException e) {
    // do something with the exception
    return; // this prevents the rest of the method from execution 
            // and thereby stops the service
  }
  // rest of your code
}

Autres conseils

IntentService stops automaticlly after finishing OnHandleIntent. There is no need to do it manually.

Read description of method onHandleIntent()

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top