Search code examples
androidserviceexecution

Ensure android service Execution


I have an Android service which I start from the main activity. The service is really simple, it has a simple timetask which checks for an update about some information every 10-15 minutes.

When the android device is connected to USB the task is executed perfectly and everything is great. If I unplug the USB cable, the task isn't executed.

Why does this only work when the USB cable is connected?


Solution

  • Using a Service for this task is not recommended as the service keeps running in the background even if there is nothing to do. Best way is to use an AlarmManager to call the service. Here is a tutorial on how to use AlarmManager:

    http://justcallmebrian.com/?p=129

    When the service is done performing its task, you can schedule the AlarmManager again.