从我的“MainActivity”调用一个方法在安卓中
我目前正在搞乱 Google 的 C2DM 通知服务。 请按照本教程中的步骤操作: http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/ article.html,我成功收到服务器发来的“推送消息”。 但是,在“protected void onMessage”中,我需要将消息发送到“MainClass”以在祝酒词中打印它。由于我对 Android 开发不太熟悉,因此我将不胜感激。谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用广播与活动进行通信。
onMessage
中发送广播。onResume
中注册一个广播接收器并使其显示一个toast(记住在onPause
中取消注册它)您还需要处理活动不存在时的情况正在运行(可能会显示通知)。在这种情况下,使广播成为有序广播。活动中的广播接收器应设置为高优先级,然后通过清单注册默认广播接收器(此接收器显示通知,或打开活动,或任何您想要的)。
Use a broadcast to communicate with the activity.
onMessage
send a broadcast.onResume
register a broadcast receiver and make it display a toast (remember to unregister it in theonPause
)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).