我今天正在测试如何使用gcm。它工作正常,但我得到双重通知。
我对双重通知的意思是在通知发出几分钟后,第二次通知的内容与第一次完全相同。
我正在使用GCM with PHP (Google Cloud Messaging)
测试通知我不知道我哪里出错了......我正在使用模拟器和真实设备进行测试 这是logcat调试
02-27 16:05:36.192: V/GCMBroadcastReceiver(513): onReceive: com.google.android.c2dm.intent.RECEIVE
02-27 16:05:36.192: V/GCMBroadcastReceiver(513): GCM IntentService class: mypackage.GCMIntentService
02-27 16:05:36.201: V/GCMBaseIntentService(513): Acquiring wakelock
02-27 16:05:36.221: V/GCMBaseIntentService(513): Intent service name: GCMIntentService-DynamicSenderIds-2
02-27 16:05:36.312: V/GCMBaseIntentService(513): Releasing wakelock
.
.
.
02-27 16:11:14.282: V/GCMBroadcastReceiver(513): onReceive: com.google.android.c2dm.intent.RECEIVE
02-27 16:11:14.282: V/GCMBroadcastReceiver(513): GCM IntentService class: mypackage.GCMIntentService
02-27 16:11:14.291: V/GCMBaseIntentService(513): Acquiring wakelock
02-27 16:11:14.302: V/GCMBaseIntentService(513): Intent service name: GCMIntentService-DynamicSenderIds-3
02-27 16:11:14.402: V/GCMBaseIntentService(513): Releasing wakelock
答案 0 :(得分:1)
验证您只注册一次BroadcastReceiver,因为每次注册BroadcastReceiver时都会触发它。例如,如果您在onResume
的{{1}}方法中注册,但未在Activity
方法中取消注册,则会遇到问题。