Dave Bordoley wrote:
> I'm starting to write an app that will periodically poll an HTTP
> resource and use the data to update a View. My initial thought process
> on how this will work is that on application startup, my activity will
> spawn a worker thread that will maintain an object model of the data
> and update it as necessary.

Use AsyncTask.

> Ideally this thread would publish back to
> the UI thread that the data has changed and the UI thread would read
> the object model and update the view.

Use AsyncTask!

> I'm not too familiar with
> Android's architecture to support threading and messaging between
> threads, so I was wondering if there was a good up to date tutorial
> etc. that someone could point me to.

Use AsyncTask!!!

> ps. In the past I've used AsyncTask but i don't think it will meet my
> requirements as the UI thread would need to maintain a timer to kick
> off an AsyncTask. Ideally I'd like to isolate these two parts of the
> application as much as possible.

IMHO, that's not a good justification to skip AsyncTask.

First, threads aren't usually really objects, insofar as "threads" don't
manage models -- objects do. The object that manages your local copy of
the remote data can have its timer (TimerTask, AlarmManager with a
service, Handler#postDelayed, etc.) and use AsyncTask for the actual
work once the timer triggers. You can use encapsulation to maintain your
isolation between the UI and the timer/thread object.

If you're fairly certain you will have a single activity, I would:

-- Create a class to handle your timer/thread work, plus the AsyncTask
implementation

-- Put a Handler object in your activity

-- Pass the Handler to the timer/thread object in its constructor, along
with whatever sorts of listeners you're going to use to notify the UI of
changed data

-- Call postDelayed() on the Handler, where the Runnable supplied to
postDelayed() schedules the next timer tick (via another call to
postDelayed()) and kicks off an AsyncTask to do the heavy lifting

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Training: http://commonsware.com/training.html

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to