C2DM getting the same message

有些话、适合烂在心里 提交于 2019-12-11 07:36:33

问题


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

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.

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

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.


回答1:


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.

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);

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

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




回答2:


I had the same problem when following Lars Vogel's tutorial. Most probably you have the same problem, i.e. you actually receive the good message but the Activity that shows it is not working as it should.

To ensure that you are receiving the good message, put a breakpoint or a log in the onReceive function, and see what you get.

If you do receive different messages, then your problem is the same as mine: improper showing of the message.

The MessageReceivedActivity from Vogel's tutorial calls the super.onCreate(savedInstanceState); on the end of the method, when it should be calling it first thing in that method. See my detailed solution to a related question here.




回答3:


Check you're not misusing the collapse_key as that could potentially cause what you're seeing.

I've used C2DM a fair amount, and I've never seen this. I often send a sequence of messages one after the other, and they arrive ok.

I'd also double-check to make sure you are receiving the message you think you are - look at the intent parameters.



来源:https://stackoverflow.com/questions/9958569/c2dm-getting-the-same-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!