Android: How to schedule a Background Service to run repeatedly
<p>I have a AsyncTask in a Service which gets RSS feeds and stores them in the SQLiteDatabase. The service is started from the main Activity. I need the AsyncTask to be executed say after every 4 hours or so to pull the RSS feeds. I tried using the TimerTask as below but this does not seem to be working. The background task is run just once. Any ideas on how to best implement this scenario/any alternatives?</p>

<pre><code>public class FeedReader extends Service{

    private void getFeedsRegularly() {
        timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
        handler.post(new Runnable() {

        @Override
        public void run() {
            new BgTask().execute(feedURL);

        }
            });
            }
    }, 0, UPDATE_INTERVAL);
    }

    private class BgTask extends AsyncTask&lt;...&gt; 
    {...}
}
</code></pre>
