Hi Lew,

Yeah, my terminology was a bit off.

I've got a class, an instance of which is run at program start:

public class ServerPushActivity extends Activity {
        ListView listView1;
        LogItemAdapter logItemAdapter;
        ArrayList<LogRecord> logs;

        public void updateList(){

        }
}

The updateList() function adds some items to the local ArrayList and
uses that to populate a ListView.

Then I have another Class which is triggered by the C2DM call:
public class C2DMMessageReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {

        }
}

What I need is some way of getting the C2DMMessageReceiver.onRecieve()
function to run the ServerPushActivity.updateList() function against
the instance of ServerPushActivity that is created when the program
starts.

I'm thinking I need to do something with Intents, or I could be coding
the thing completely the wrong way and I need to move my data store
out of a variable local to the main function. It's a problem with
doing a fair amount of coding in the past (C, VB, PHP, etc), but this
is my first Android app, so I'm not used to all the android specific
bits.

Matt

On Mar 27, 7:29 pm, Lew <lewbl...@gmail.com> wrote:
> Matt Green wrote:
>
> > I've not been doing Android (or Java) programming very long, so I'm
> > still getting my head around the android/Java specific features.
> > I'm trying to integrate C2DM into a simple app I've made.
>
> > My current app grabs some JSON data and puts it into a ListView, this
> > is all handled within a single class. My app then polls the ser ver
> > regularly to see if there are any updates to the data.
>
> > I've then had a go at integrating C2DM into my app by adding in
> > classes and buttons from the C2DM tutorial at vogella.de (http://
> >www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html)
>
> > This works, I can get a message through telling me that there is new
> > data, however, I can't see how to integrate it any further.
>
> > What I want to do is have the C2DM class trigger a function in my main
> > class that will go collect the new data.
>
> > Any ideas what I should do?
>
> I am not familiar with C2DM but I can discuss the general Java idioms for
> this.
>
> The two most common mechanisms are polling and callbacks.
>
> A poller loops around, perhaps after a delay each cycle, usually in a
> background thread, checking for a desired state. After detecting that
> state, or after a timeout, the poller returns.
>
> A callback implements an interface that the service knows about. The
> service calls the known method on the callback object.
>
> By the way, unless you are using 'static' methods, and not really even
> then, a class doesn't call another class. An instance calls methods on an
> instance.
>
>  public interface FooListener
>  {
>    void doSomething( Gromitz gromitz );
>  }
>
>  public class FooClient implements FooListener, Runnable
>  {
>    private final transient Logger logger = getLogger(getClass());
>
>    private final FooService service = obtainFooService();
>
>    private Framxeg framxeg;
>
>    @Override public void doSomething( Gromitz gromitz )
>    {
>       framxeg = gromitz.getFramxeg();
>    }
>
>    public void init()
>    {
>       service.setListener(this);
>    }
>
>    @Override public void run()
>    {
>      if (service.getListener() != this)
>      {
>        IllegalStateException exc = new
> IllegalStateException("uninitialized");
>        logger.error(exc);
>        throw exc;
>       }
>       service.doYourThing();
>    }
>
>    public Framxeg getFramxeg()
>    {
>      return framxeg;
>    }
>  }
>
> --
> Lew

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

Reply via email to