Android:在推送通知上更新堆栈上的活动
因此,我有一个具有多个可以在堆栈上的活动的应用程序。值得注意的是,活动游戏列表和显示特定游戏的活动。
当 C2DM 消息到达时,我目前仅在状态栏中显示通知,但我希望 GameList 或 GameActivity 更新(如果它们正在运行)。
有没有办法获取应用程序正在运行的活动?或者有更好的方法来实现这一点吗?我看到一段使用意图触发事件的代码片段,我应该按照这些思路做一些事情吗?
(或者,愚蠢的我,这个想法刚刚出现在我身上:我可以让我的项目中的多个类接收 C2DM 消息,并检查它是否适用于它们吗?)
谢谢。
So, I have an application with multiple activities that can be on the stack. Notably, a list of active Games and an activity showing a particular Game.
When a C2DM message arrives, I currently just show a notification in the status bar, but I'd like to have the GameList or GameActivity update if they are running.
Is there a way to get an Application's running Activities? Or is there a preferred way to accomplish this? I saw a snippet of code to fire off events using Intents, should I do something along those lines?
(Or, silly me, this thought just occurred to me: Can I have multiple Classes in my Project receive the C2DM message, and check if it applies to them?)
Thank you.
如果您想更新当前的活动,您可以在活动中拥有一个接收器,但是如果您想更新堆栈中已经存在的活动,您可以创建一个单独的接收器来更改某些首选项值,当活动显示时,您可以检查此首选项更新您的活动。
If you want to update your current activity you could have a receiver within your activity but if you want to update an activity is already in the stack you could make a separate receiver that change some preference value and when the activity displayed you could check this preference to update your activity.