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. how to place a landmark on a google map programmatically

Hello ev1 !! I am working on google maps and being a beginner to
android face problems in beginning. I have learnt to place a marker on
a location programmaticaly but now i want to place a landmark type
balloon where i want it to be. so that when it is clicked particular
information is displayed about the location. Kindly help me out !!

Regards,
wahib

2. AlarmManager and the PendingIntent that failed

In order to learn how to use the AlarmManager I created an activity
that consists of a single button. When the button is pressed the
activity creates an Intent of itself and loads it into the
AlarmManager 3 seconds in the future before finishing.

So activity opens, user pushes button, activity closes, 3 seconds
later activity opens, repeat.

Problem is instead of opening the activity 3 seconds later I get an
error: "The application [myappname] has stopped unexpectedly. Please
try
again." however I was able to open a Toast from the Receiver just
fine.


Here's the code for the button:
thanksButton.setOnClickListener(new View.OnClickListener() {
               public void onClick(View view) {
               setResult(RESULT_OK);

               Intent intent = new Intent(myappname.this,
myappnameBroadcastReceiver.class);
               PendingIntent appIntent = PendingIntent.getBroadcast
(myappname.this, 0, intent, 0);
               Calendar calendar = Calendar.getInstance();
               calendar.setTimeInMillis(System.currentTimeMillis());
               calendar.add(Calendar.SECOND, 3);
               AlarmManager am = (AlarmManager)getSystemService
(ALARM_SERVICE);
               am.set(AlarmManager.RTC, calendar.getTimeInMillis(),
appIntent);

               finish();
               }

       });

--------------------------------------------
Here's the broadcast receiver:
package com.myappname;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class myappnameBroadcastReceiver extends BroadcastReceiver {
       @Override
       public void onReceive(Context context, Intent intent) {
                       context.startActivity(new Intent(context,
myappname.class));
       }
}

---------------------------------------------
and here's the lines from the manifest.xml

               <receiver
                       android:name=".myappnameBroadcastReceiver"
                       android:process=":remote">
               </receiver>

3. Looking for some reading on the Android Framework

4. Macro Recording

5. Android Emulator Problems on Win2K

6. Regarding Multimedia

7. Android 2.0 SDK is here!