3

I've got a simple question: I'm using commonsware's wakefulintentservice in my application and I got it working, but how do I know if the WakefulIntentService is still running or not? Can I for example put a onDestroy in the WakefulIntentService class and let that log something or is there another way to see wheter the WakefulIntentService is running or not?

Thanks in advance!

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Xander
  • 5,487
  • 14
  • 49
  • 77

1 Answers1

4

I'm using commonsware's wakefulintentservice in my application and I got it working, but how do I know if the WakefulIntentService is still running or not?

If you mean "is it ever running", you see whether the work that it is supposed to do is getting done.

If you mean "is it running right this moment", examine your threads in DDMS, I suppose. I have never really worried about this question.

Can I for example put a onDestroy in the WakefulIntentService class and let that log something

Sure.

UPDATE

Also, adb shell dumpsys activity services will list the active services. I have not tried this with a WakefulIntentService, but AFAIK it should show up there.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • @Merlin: I thought of another option -- see the updated answer. – CommonsWare Oct 12 '12 at 15:35
  • One more little question: Can I call an AsyncTask from my doWakefulWork method or should I avoid that? – Xander Oct 12 '12 at 15:38
  • @Merlin: It should not be needed, as `doWakefulWork()` is already on a background thread. And, once `doWakefulWork()` ends, not only might the device fall asleep, but Android might terminate the process -- either of which may be bad for your background thread. Hence, I do not recommend starting an `AsyncTask` from `doWakefulWork()` (or `onHandleIntent()` of an ordinary `IntentService`). – CommonsWare Oct 12 '12 at 15:40
  • I advise against using logging in the service's `onDestroy()` method, as it is not guaranteed to execute. – Piovezan Jun 18 '13 at 17:12