C2DM得到相同的消息 [英] C2DM getting the same message

查看:153
本文介绍了C2DM得到相同的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名学生,我开发一个Android应用程序为我的软件设计过程中的一个项目。

Hi I'm a student and I'm developing an android app as a project for my software design course.

所以,我管理,使整个过程C2DM工作,以及我的设备可以接收通知。但是我得到的消息总是每次都在同我推的东西,即使我把不同的信息。

so, I manage to make the whole C2DM process works, and my device can receive the notifications. However the message that I get is always the same every time I push something even though I push a different message.

我在下面这里提到的教程:
  http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html

I'm following the tutorial mentioned here: http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html

有时我得到正确的消息,但是我不得不等待30分钟以上,推动新的消息。多少时间我有另外一个推消息之前要等待?
 (我试了一下等待时间为2分钟,但我得到了同样的信息),或者是有什么我做错了。

Sometimes I do get the correct message however I have to wait for more than 30 min to push a new message. How much interval do I have to wait before pushing another message? (I tried it 2 min of waiting time but I get the same message) or is there something I'm doing wrong.

推荐答案

一个问题,其中一个未决的意图与相同情况下,请求code,意图创建教程code存在,标志与现有调用,并且它被处理后不会取消。这样收件人(MessageReceivedActivity)显然是引用了previous的PendingIntent。

A problem exists with the tutorial code where a pending intent is created with identical context, requestCode, intent, and flags as the prior call, and not cancelled after it is handled. So the recipient (MessageReceivedActivity) apparently references the previous PendingIntent.

解决此问题的方法:
该请求code'的属性还没有使用,所以使的PendingIntent唯一可以提供独特的价值存在,例如:

One way around this: The 'requestCode' attribute is not currently used, so to make the pendingIntent unique you can supply a unique value there, for example:

int ukey = (int) System.currentTimeMillis();
PendingIntent pendingIntent = PendingIntent.getActivity(context, ukey,
                intent, 0);

这将使MessageReceivedActivity得到您打算(双关语意/ :)它来接收。意图

This will allow the MessageReceivedActivity to get the intent that you intend (pun intended /:) for it to receive.

也许有办法取消的PendingIntent,但我不能让它工作了。

Maybe there is a way to cancel the pendingIntent, but I couldn't make it work out.

这篇关于C2DM得到相同的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆