How to schedule a background task
<p>There seems to be a couple of ways to go about having a background task being executed. My usecase is to have my app fetch a datafeed every x minutes, regardless of my gui is running, and regardless of whether the phone is sleeping or not.</p>

<p>I use an alarmmanager to schedule an intent matching a broadcastreceiver. in the onRecieve method i start a service (startService), which spawns an AsyncTask. The task fetches data and stores it and then stopSelf() the service.</p>

<p>in the onRecieve method i aquire a PARTIAL_WAKE_LOCK, before starting the service, and just before calling stopSelf() in the service, i release it again.</p>

<p>Is this really the best way to do it? Do i even need the service in this scenario?</p>

<p>I experience odd behaviour with this setup, where the setup works for hours and then suddenly stops, which makes it very hard to debug.</p>

<p>Does anyone have a simple foolproof method to achive the same end?</p>
