Service updating things in a Activity (different threads)

Put your problem here if it does not fit any of the other categories.

Service updating things in a Activity (different threads)

Postby Mr Fix It » Tue Jun 29, 2010 3:22 pm

Howdy.

I've can't seem to figure out how to update the GUI from a serviced thread.

Basically my app is going to be scraping a webpage every *user defined* interval. So i want the scraper to run in the background etc. However when it's done, i'd want it to print the result in the activity/GUI thread.

How would i go about doing this?
Mr Fix It
Freshman
Freshman
 
Posts: 3
Joined: Tue Jun 29, 2010 3:17 pm

Top

Re: Service updating things in a Activity (different threads

Postby alexm » Tue Jun 29, 2010 6:26 pm

You could use a broadcast from your service to notify that the GUI that there is a new page waiting to be viewed.

Use a broadcast receiver in your GUI to catch the broadcast and do the correct things.
alexm
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Jun 22, 2010 7:34 am

Re: Service updating things in a Activity (different threads

Postby vik » Tue Jun 29, 2010 6:53 pm

yes a handler or broadcast reicever will do...
for minor background changes it easier to use handler
User avatar
vik
Senior Developer
Senior Developer
 
Posts: 141
Joined: Wed Sep 09, 2009 7:32 am

Re: Service updating things in a Activity (different threads

Postby Mr Fix It » Wed Jun 30, 2010 4:46 pm

Thanks for responses. I stumbled on the solution myself

I did use a broadcast reciever. I'm actually liking this because if i build a widget i should be able to code it to respond to the same broadcasts rather easily.

I'm also using a handler to talk to the service (once running), eg sending a message to request the data the service has cached. Which in turn makes the service send a broadcast of the cached data.
Mr Fix It
Freshman
Freshman
 
Posts: 3
Joined: Tue Jun 29, 2010 3:17 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests