How to update the GUI in Push/C2DM sample from advandroid book?

15 views
Skip to first unread message

dotnetdriver

unread,
Sep 13, 2010, 7:25:59 AM9/13/10
to cw-android
Hi,
I have got the C2DM example working but I just need one more thing
to be finished.

My payload is appearing in onMessage() in C2DMReceiver.java

Now I just want to update the GUI from this method.

Can I somehow call a method in PushEndpointDemo.java?

Do I need a Broadcast Intent to do this?

Any advice appreciated.

Thanks.

Mark Murphy

unread,
Sep 13, 2010, 7:36:51 AM9/13/10
to cw-an...@googlegroups.com
On Mon, Sep 13, 2010 at 7:25 AM, dotnetdriver <jude...@googlemail.com> wrote:
>  I have got the C2DM example working but I just need one more thing
> to be finished.
>
> My payload is appearing in onMessage() in C2DMReceiver.java

Correct.

> Now I just want to update the GUI from this method.
>
> Can I somehow call a method in PushEndpointDemo.java?

No, for two reasons:

1. Because C2DMReceiver is a manifest-registered BroadcastReceiver and
therefore has no access to any activities

2. There might not be an activity, since you have no control over the
timing of when the C2DM message is received (e.g., the user pressed
BACK, the user pressed HOME)

> Do I need a Broadcast Intent to do this?

Possibly.

-- If you want to update an activity or else ignore the message, have
C2DMReceiver send out a private broadcast, picked up by a receiver
registered via registerReceiver() in the activity

-- If you want to update an activity or else raise a notification,
have C2DMReceiver send out an ordered broadcast, as described here:

http://commonsware.com/blog/2010/08/11/activity-notification-ordered-broadcast.html

-- If you want to update a database, call startActivity() on an
IntentService, and have it do the database I/O, plus possibly
broadcast an Intent to update an activity/raise a notification.

Et cetera.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training...At Your Office: http://commonsware.com/training

dotnetdriver

unread,
Sep 13, 2010, 8:25:53 AM9/13/10
to cw-android
Thanks a million.. again :)
Your advice is very much appreciated.

On Sep 13, 12:36 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> On Mon, Sep 13, 2010 at 7:25 AM, dotnetdriver <judere...@googlemail.com> wrote:
> >  I have got the C2DM example working but I just need one more thing
> > to be finished.
>
> > My payload is appearing in onMessage() in C2DMReceiver.java
>
> Correct.
>
> > Now I just want to update the GUI from this method.
>
> > Can I somehow call a method in PushEndpointDemo.java?
>
> No, for two reasons:
>
> 1. Because C2DMReceiver is a manifest-registered BroadcastReceiver and
> therefore has no access to any activities
>
> 2. There might not be an activity, since you have no control over the
> timing of when the C2DM message is received (e.g., the user pressed
> BACK, the user pressed HOME)
>
> > Do I need a Broadcast Intent to do this?
>
> Possibly.
>
> -- If you want to update an activity or else ignore the message, have
> C2DMReceiver send out a private broadcast, picked up by a receiver
> registered via registerReceiver() in the activity
>
> -- If you want to update an activity or else raise a notification,
> have C2DMReceiver send out an ordered broadcast, as described here:
>
> http://commonsware.com/blog/2010/08/11/activity-notification-ordered-...
>
> -- If you want to update a database, call startActivity() on an
> IntentService, and have it do the database I/O, plus possibly
> broadcast an Intent to update an activity/raise a notification.
>
> Et cetera.
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
Reply all
Reply to author
Forward
0 new messages