调用GCMRegistrar.register当泄漏的IntentReceiver错误() [英] Leaked IntentReceiver error when calling GCMRegistrar.register()
问题描述
我试图完成对谷歌的GCM 从谷歌的Android开发者网站。
在我的设备尝试注册,它失败,原因如下:
活动已经从com.google.android.gcm.GCMBroadcastReceiver最初注册到了这里泄露IntentReceiver。是否缺少调用unregisterReceiver?
这是在code:
GCMRegistrar.checkDevice(本);
GCMRegistrar.checkManifest(本);
最后弦乐REGID = GCMRegistrar.getRegistrationId(本);
如果(regId.equals()){
GCMRegistrar.register(这一点,senderId); //< - 它无法在这里
} 其他 {
Log.v(GCM,已登记);
}
你知道吗?
我是什么做错了吗?
更新
这是我的清单:
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.sample
安卓版code =1
机器人:VERSIONNAME =1.0>
<使用-SDK安卓的minSdkVersion =8/>
<允许机器人:名称=com.sample.permission.C2D_MESSAGE安卓的ProtectionLevel =签名/>
<使用-权限的Android:名称=android.permission.ACCESS_FINE_LOCATION/>
<使用-权限的Android:名称=android.permission.ACCESS_COARSE_LOCATION/>
<使用-权限的Android:名称=android.permission.INTERNET对/>
<使用-权限的Android:名称=android.permission.GET_ACCOUNTS/>
<使用-权限的Android:名称=com.google.android.c2dm.permission.RECEIVE/>
<使用-权限的Android:名称=com.sample.permission.C2D_MESSAGE/>
<使用-权限的Android:名称=android.permission.WAKE_LOCK/>
<应用
机器人:图标=@可绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME>
<活动
机器人:样品NAME =
机器人:标签=@字符串/ APP_NAME>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动机器人:主的主题=@机器人:款式/ Theme.NoTitleBar机器人的名字=机器人:screenOrientation =画像/>
<接收器的Android版本:NAME =com.google.android.gcm.GCMBroadcastReceiver安卓权限=com.google.android.c2dm.permission.SEND>
<意向滤光器>
<作用机器人:名称=com.google.android.c2dm.intent.RECEIVE/>
<作用机器人:名称=com.google.android.c2dm.intent.REGISTRATION/>
<类机器人:名称=com.sample/>
&所述; /意图滤光器>
< /接收器>
<服务机器人:名称=com.sample.GCMIntentService/>
<使用库机器人:名称=com.google.android.maps/>
< /用途>
< /舱单>
最后,它的工作原理。
所有我需要做的是呼吁 GCMRegistrar.onDestroy(本)
在的onDestroy()
方法同样的情况下我打电话 GCMRegistrar.register()
在这里找到:<一href="http://stackoverflow.com/questions/11299312/leaked-intentreceiver-in-google-cloud-messaging">Leaked IntentReceiver在谷歌云消息传递
感谢您的支持:)
I'm trying to finish the getting started steps on Google's GCM from Google's Android Developer site.
When my device tries to register, it fails with the following reason:
Activity has leaked IntentReceiver from com.google.android.gcm.GCMBroadcastReceiver that was originally registered here. Are you missing a call to unregisterReceiver?
This is the code:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, senderId); // <-- It fails here
} else {
Log.v("GCM", "Already registered");
}
Any idea?
What am I doing wrong?
Update
This is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<permission android:name="com.sample.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.sample.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".sample"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:theme="@android:style/Theme.NoTitleBar" android:name=".Main" android:screenOrientation="portrait" />
<receiver android:name="com.google.android.gcm.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="com.sample" />
</intent-filter>
</receiver>
<service android:name="com.sample.GCMIntentService" />
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
Finally it works.
All I need to do is call to GCMRegistrar.onDestroy(this)
in the onDestroy()
method in the same Context I'm calling GCMRegistrar.register()
Found here: Leaked IntentReceiver in Google Cloud Messaging
Thanks for your support :)
这篇关于调用GCMRegistrar.register当泄漏的IntentReceiver错误()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!