Skip to content Skip to sidebar Skip to footer

Android - How To Run A Task Via "handler" Periodically Within A Service-intent (worker-thread)

My question is Android related: How do I run a task every 20 seconds within an intentservice ? Problem is, I have to init some classes which will be used in the Handler 'run' proce

Solution 1:

How do I run a task every 20 seconds within an intentservice ?

That is not an appropriate use of IntentService. Use a regular Service, please.

It works one time - but then the service stops & the application crashes when the handler-loop starts again after 20 seconds

IntentService shuts down when onHandleIntent() returns, which is why this is breaking for you. Use a regular Service, please.

Also:

  • Please allow the user to configure the polling period
  • Make sure that this service will shut down when the user no longer wants it to be running

Post a Comment for "Android - How To Run A Task Via "handler" Periodically Within A Service-intent (worker-thread)"