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 [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

Reply via email to