periodic updates of ListView

by kingkung » Tue, 13 May 2008 16:41:36 GMT


Sponsored Links
 Hey all,

I was just hoping to get some suggestions on the best way to implement
this...

I have a ListView containing a list of objects with TextViews.  I want
to periodically update these TextViews on a periodic basis in the
background (I make an http post request to a server to receive the
updated text, and then insert it into the text view).  I don't want
the periodic updating of these views to interfere with the user
experience.

There are several ways I could think about doing this... either
through using a Service which I call periodically, a Service which
periodically sends updates (though I dunno if a Service can update an
Activity's list view), or spinning off a separate Thread from the
original Activity.

Does anyone have any suggestions which option would be optimal, and
why?

Thanks,

James

--~--~---------~--~----~------------~-------~--~----~



periodic updates of ListView

by Mark Murphy » Tue, 13 May 2008 17:40:25 GMT


 > I have a ListView containing a list of objects with TextViews.  I want

If you want to collect the data via HTTP regardless of whether the
activity is visible, hidden, or killed off (e.g., due to low RAM), then
the Service is the way to go. The activity could either poll the service,
or the Service could raise an Intent that the activity receives to trigger
the screen update. In the latter case, though, be sure to use a Handler so
the screen update happens on the UI thread -- Android, like Swing,
requires all UI updates be performed on the magic UI thread.

If you want the data to be potentially available to other applications,
besides your own (e.g., your Service is fetching RSS/Atom feeds), then a
Service is the way to go.

If everything is truly local to the activity, then a background thread and
Handler could work.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
The Busy Coder's Guide to Android Development -- coming in June 2008!


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Open new window by pressing button.

Hi

Now I faced opening new window problem.
I've learned how to make custom window from below link
http://developer.android.com/guide/topics/ui/dialogs.html#ShowingADialog

But I open it by press button from main window.
Also that window can store some information to DB too.


Thanks in advance
Dan

--~--~---------~--~----~------------~-------~--~----~

2. Practical questions

Hi all,

I have some practical questions.

I might be interested in coding for Android. I have some J2ME programs
that I could port that are very useful.

But I am wondering, why bother? Consider:

1.
Looking at the documentation for Android it seems to me that the
learning curve for working with Android is large.

2.
Looking at the available phones they are all about $500 without a
contract. The USA is in a Recession and $500 is a lot of money.
Compare that to my 3-inch touch screen Sciphone i68+ which cost me
$100 and has MIDP support.

3.
I don't do phone contracts. I have heard that Android phones are
hobbled by the requirement that I'd have to have a contract. I use
prepaid exclusively to keep my phone bills down.

4.
No contract means no data plan. I'm under the impression that the
phone would be hobbled without a data plan.

5.
I can get a Windows Mobile phone for $260, called the CECT M88+. It
will run native apps and J2ME. That's half the cost of an Android
phone.

6.
Regular consumers know we're in a recession. They are going to avoid
expensive phones and long contracts more now than ever. Will $500
luxury Android phones take hold? I'm skeptical.

7.
I am not someone who is easily impressed by Google. There is no "wow"
factor for me in using Android. I'm entirely pragmatic.

Thanks.





--~--~---------~--~----~------------~-------~--~----~

3. Can't get my hello world application to run on the emulater!

4. Can I just redraw part of the view without clean the existed pic?

5. What is "Contact Source" and how to manipulate it?

6. Applying effects to sounds

7. Where I can get royalty free pictures?