gpt4 book ai didi

android - 调用 GCMRegistrar.register() 时泄漏的 IntentReceiver 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:58:46 26 4
gpt4 key购买 nike

我正在努力完成 Google's GCM 上的入门步骤来自 Google 的 Android 开发者网站。

当我的设备尝试注册时失败,原因如下:

Activity has leaked IntentReceiver from com.google.android.gcm.GCMBroadcastReceiver that was originally registered here. Are you missing a call to unregisterReceiver?

这是代码:

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

有什么想法吗?

我做错了什么?

更新

这是我的 list :

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

最佳答案

终于成功了。

我需要做的就是在 onDestroy() 方法中调用 GCMRegistrar.onDestroy(this),与调用 GCMRegistrar 的上下文相同。注册()

在这里找到:Leaked IntentReceiver in Google Cloud Messaging

感谢您的支持:)

关于android - 调用 GCMRegistrar.register() 时泄漏的 IntentReceiver 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11278464/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com