gtdevel
gtdevel

Reputation: 1513

Manually ending the IntentService worker thread

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?

Upvotes: 4

Views: 3444

Answers (2)

whlk
whlk

Reputation: 15635

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
}

Upvotes: 2

Jakub Szczygieł
Jakub Szczygieł

Reputation: 1222

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

Read description of method onHandleIntent()

Upvotes: 1

Related Questions