Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6360799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:41:41+00:00 2026-05-24T23:41:41+00:00

Basically i am developing a rss feed for android, and i want to have

  • 0

Basically i am developing a rss feed for android, and i want to have a updater service that, for each source, get the feeds in specific time.

Imagine:

Source1 – 5minutes
Source2 – 10minutes
Source3 – 10minutes

I build a differential list to use only one thread that make the requests for update.
The datastructure stays like this:

Source1 (next sleep – 5), Source2 (next sleep – 0, Source 3 (next sleep 5).. and so on..

What i do is, i add always to a list of providers (that contains the id and URL) and when sleep is != 0, i order the update (that uses async task, i pass the list of providers to update, and asynctask do the job for me, that is… go to internet, parse content, and update database)

but exists one worker thread that is sleeping just for the sake of group a bundle of providers and sent to AsyncTask to update.

What’s the problem..
First the thread don’t sleep for the specific time, the thread must sleep 10 minutes, i made a method for convert minutes to milis, that is:

private static int MinutesToMilis(int minutes) { return minutes * 1000 * 60;    }

i am using alogcat, an widget on my phone and the thread sleeps about 25 minutes (WTF) 😐

Other thing that i verified is that, when phone is charging, the service works OK…

Here is the code:

worker = new Thread(new Runnable()
    {
        @Override
        public void run() 
        {
            Provider[] enabledProviders = feedService.getAllProvidersEnabledData();     

            // Build a differential list from enabledProviders
            DifList<Provider> list = getListForProviders(enabledProviders);     

            //
            // Code starts here
            int sleep;              
            DifNode<Provider> header = list.getFirst();

            sleep = header.getInitial();
            LinkedList<Provider> data = new LinkedList<Provider>();
            Log.d(TAG, String.format("Worker thread started @ %s", now()));

            try
            {
                for(int idx = 0 ;   true    ; list.reorderFirst(), header = list.getFirst(), idx++)
                {
                    Log.d(TAG, String.format("Iteration %s with sleep %s", idx, sleep));

                    if(sleep > 0) {
                        Log.d(TAG, String.format("Next download in %s minutes", sleep));

                        // Suspend worker thread for sleep time
                        Thread.sleep(MinutesToMilis(sleep));

                        Log.d(TAG, "Worker thread waked up from sleep");
                    }

                    // Add to data
                    data.add(header.getKey());

                    // Set next sleep time
                    sleep = header.getDifference();                     


                    if(sleep != 0)
                    {
                        Log.d(TAG, "Worker preparing for update..");
                        //
                        // If difference to next is not 0 we dump data to async task
                        for(Provider p : data){
                            Log.d(TAG, String.format("Starting update %s @ %s", p.Name, now()));
                        }

                        Provider[] arrayData = new Provider[data.size()];
                        data.toArray(arrayData);

                        data.clear();
                        new UpdateBundleOfFeedsTask().execute(arrayData);
                    }


                }
            }       
            catch(InterruptedException ex)
            {
                Log.d(TAG, String.format("Worker thread was interrupted @ %s", now()));
                isRunning = false;
            }

            Log.d(TAG, String.format("Worker thread exit @ %s", now()));
        }
    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:41:41+00:00Added an answer on May 24, 2026 at 11:41 pm

    You should really not be doing it that way, ie having a thread that never dies. I strongly suggest you have a look at alarms : http://developer.android.com/reference/android/app/AlarmManager.html

    A good way to go would be :

    • set a repeating alarm, maybe one with a different pendingIntent for each client, although in your case its seems to be a little too frequent to do that each 5-10 minutes only to read some RSS.
    • implement a broadcast receiver that listens to the pending intents set by your alarm.
    • from the broadcast receiver, start a service that starts a worker thread to read from the network and save to DB.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have basically finished developing an android app that makes use of SQLite databases
I have a project for Linux that i've been developing for some time. Basically
I am developing a site that parses RSS feeds and displays them in a
I am developing a website that parses rss feeds and displays them based on
I am developing a simple RSS aggregator site that basically parses a bunch of
I'm developing a small application using Blend, basically what I have in my application
I have code running in an iPhone application I am developing. Basically, the code
Basically I have some code to check a specific directory to see if an
I know that when developing for Xbox in XNA, you basically just set the
I'm quite new to developing Android apps. Basically I'm making a webview template to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.