Hi,
I'm creating a prototype for a messaging application. Here's what I've
got so far:
1. Main list activity which show the list of received messages from
the database (public class MainAcitvity extends ListActivity)
2. On the first run the activity starts a background service in the
onCreate():
startService(new Intent(this, MessageSyncStarter.class));
3. The MessageSyncStarter service registers a repeating alarm like
this:
Intent intent = new Intent(this,
MessageSyncBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
REQUEST_CODE, intent, 0);
mAlarmManager = (AlarmManager)
getSystemService(ALARM_SERVICE);
mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + FIRST_RUN, INTERVAL, pendingIntent);
4. The MessageSyncBroadcastReceiver is the entry point to handle
network communication, fetch messages from server and put them into
database:
public void onReceive(Context context, Intent intent) {
SynchronizeMessages(context);
}
Everything works fine. The thing I don't get is - how to perform UI
refresh in the main activity (if it's on the foreground) when
MessageSyncBroadcastReceiver gets its job done?
That is: what is the correct way to let my activity know that it needs
to refresh the list.
Also: what is the correct approach to construct an applications like
this, when a background process is needed to perform a regular syncing
work and notify all interested activities to refresh their views?
Thanks.
Ilja.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en