0

I'm currently messing up with the Google's C2DM notification service. Following the steps in this tutorial: http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html, I succesfully recieved a "push message" from the server. However, in the "protected void onMessage" I need to send the message to the "MainClass" to print it in a toast. Since I'm not deeply familiarized with the Android developing, I will appreciate any help on this. Thank you

chntgomez
  • 2,058
  • 3
  • 19
  • 31

1 Answers1

0

Use a broadcast to communicate with the activity.

  1. In onMessage send a broadcast.
  2. In your activity onResume register a broadcast receiver and make it display a toast (remember to unregister it in the onPause)

You would need also to handle the case when the activity is not running (maybe display a notification). In this case, make the broadcast an ordered broadcast. The broadcast receiver in the activity should be set with a high prio, then register a default broadcast receiver through your manifest (this one displays a notification, or opens the activity, or whatever you want).

aromero
  • 25,681
  • 6
  • 57
  • 79