我的Android应用程序从不在2.3设备上接收GCM消息,但它在4.x设备上接收.我可以成功注册所有设备(2.3和4.x).我认为它可能与此问题有关,但似乎我已正确配置我的Android清单.有人能够注意我的IntentService和BroadcastReceiver,看看他们是否注意到任何问题?任何帮助将不胜感激.请注意,在我附加调试器的情况下发送通知时,永远不会为Android 2.3调用onHandeIntent().我检查了4.x设备,它们确实触发了onHandleIntent()中的调试器.谢谢!
Android Manfest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="my.package.matchtracker.permission.C2D_MESSAGE" />
<permission android:name="my.package.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my.package" />
</intent-filter>
</receiver>
<service android:name=".NotificationIntentService" android:enabled="true" />
<activity android:name="com.gigya.socialize.android.GSWebViewActivity" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> …Run Code Online (Sandbox Code Playgroud) notifications android push-notification android-2.3-gingerbread google-cloud-messaging
更新:根据我的评论,我的问题是我有一个额外的模型,我正在进入视图,我没有解除事件.当我看到事件处理程序被触发时,我假设源是来自this.model而不是this.extra_model,因为我忘记了this.extra_model也被用于错误验证.
解决方案是添加以下内容:
MyView = Backbone.extend({
//...
//add method to override BaseView
cleanUp: function() {
this.extra_model.off(null, null, this);
BaseView.prototype.cleanUp.apply(this, arguments);
},
//...
});
Run Code Online (Sandbox Code Playgroud)
感谢您查看问题,并对程序员错误表示歉意.
全部:我在清理视图后仍然遇到过陈旧/僵尸事件的问题.将自定义事件绑定到模型时会出现问题.当我从dom中删除视图时,我调用'this.model.off(null,null,this);' 正如在各种留言板上所建议的那样,但是虽然我可以看到在Chrome调试器工具中删除了"自定义处理程序"回调,但我仍然注意到"自定义处理程序"的事件处理程序被调用的次数超过它应该的次数(每次都有一次额外的)在触发事件时,我在清理后重新创建视图.有人能告诉我清理代码是否丢失了吗?提前致谢!
BaseView = Backbone.extend({
//...
displayErrors:function(){},
cleanUp: function(){
if (this.model) this.model.off(null, null, this);
if (this.collection) this.collection.off(null, null, this);
if (!this.options.persistDataAfterViewCleanup) {
if (this.model) delete this.model;
if (this.collection) delete this.collection;
}
//_.each(this.subViews, function(view){view.cleanUp();}); not needed yet.
this.undelegateEvents();
$(this.el).removeData().unbind();
//Remove view from DOM
this.$el.html('');
this.remove();
}
});
MyView = BaseView.extend({
initialize: function(){
//called manually from model using trigger …Run Code Online (Sandbox Code Playgroud)