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

  • SEARCH
  • Home
  • 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 6550877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:16:08+00:00 2026-05-25T12:16:08+00:00

I am trying to poll a given website periodically for information and then in

  • 0

I am trying to poll a given website periodically for information and then in turn update the UI in an Android app.

I have set something up similar to the following, but it just seems cumbersome. I guess my two specific questions would be:

  1. Is the view.post(new Runnable()); necessary or are the broadcasts handled on the UI thread (allowing the AsyncTask to be executed directly since it must be done from the UI)?

  2. Is there any way to periodically start an AsyncTask (or something comparable) besides setting up the alarms and receiving the Intents?

Here is a simplified version of what I am running:

public class WebUpdates extends BroadcastReceiver
{

private AlarmManager am ;
private PendingIntent pi ;
private View view ; 
private Context listener ; 

public WebUpdates(Context listener, View view)
{
    this.listener= listener; 
    this.view = view ;

    am = (AlarmManager)listener.getSystemService(Context.ALARM_SERVICE) ;
    pi = PendingIntent.getBroadcast((Context)listener, 0, new Intent("WEBUPDATE"), 0) ;

    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, (long)15000, pi) ;
}

@Override
public void onReceive(Context context, Intent intent) 
{
    view.post(new Runnable() {
        public void run()
        {
            new WebUpdateTask().execute() ;
        }
    }) ;
}

private class WebUpdateTask extends AsyncTask<Void, Void, Void>
{
    @Override
    protected Void doInBackground(Void... v) 
    {
        // bunch of web stuff... 
    }

    public void onPostExecute(Void v)
    {
        view.doBunchOfUpdates() ;
    }
}
}

This is my first question, so I apologize for for any formatting issues. Any input or help would be much appreciated!

  • 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-25T12:16:09+00:00Added an answer on May 25, 2026 at 12:16 pm
    1. According to the documentation, onReceive() exceutes on the main thread. So you ought to be able to start the AsyncTask directly.
    2. Another option would be to use Timer and TimerTask. There are a number of examples on the web, here is one. AlarmManager is better if you need to receive the Intent even when your Activity is not active. Timer and TimerTask might be better if you only need the periodic behavior while your Activity is running. Oh and I guess ScheduledThreadPoolExecutor is preferred for new code; I’ve just used Timer/TimerTask in the past.

    But I don’t think there is any harm in using AlarmManager even if you only need to update when your app is being used, as long as you cancel the alarm in onPause().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php/mysql poll that I'm trying to modify. It sets a unique
Trying to setup a simple Thread/Poll table mapping. Here is what I have: Threads
Unix/C question here. I have multiple sockets that I am trying to poll for
I have several timers that poll information off the internet. When I get an
I'm been trying to poll from a set of named-pipes for a little while
I'm trying to create a simple poll function using php and sql. I have
I am working with a codec and am trying to poll the state of
I am trying to make frontpage and want to show a poll node on
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
I'm trying to poll a script every few seconds. The script will return a

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.