在Signing In
之后我开始MainActivity
然后我添加了gcm,如下所示:
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context);
boolean sentToken = sharedPreferences
.getBoolean(Constants.SENT_TOKEN_TO_SERVER, false);
if (sentToken) {
Log.d(TAG, "Token retrieved and sent to server!");
} else {
Log.d(TAG, "An error occurred while either fetching the InstanceID token,\n" +
" sending the fetched token to the server or subscribing to the PubSub topic. Please try\n" +
" running the sample again.");
}
}
};
registerReceiver();
if (checkPlayServices()) {
// Start IntentService to register this application with GCM.
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
然后发生了错误
03-18 06:51:38.279 19336-19336/com.domain.example E/ActivityThread: Activity com.facebook.FacebookActivity has leaked ServiceConnection com.google.android.gms.common.zza@4210c6a0 that was originally bound here
android.app.ServiceConnectionLeaked: Activity com.facebook.FacebookActivity has leaked ServiceConnection com.google.android.gms.common.zza@4210c6a0 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:970)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:864)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1786)
at android.app.ContextImpl.bindService(ContextImpl.java:1769)
at android.content.ContextWrapper.bindService(ContextWrapper.java:536)
at com.google.android.gms.common.stats.zzb.zza(Unknown Source)
at com.google.android.gms.common.stats.zzb.zza(Unknown Source)
at com.google.android.gms.ads.identifier.AdvertisingIdClient.zzp(Unknown Source)
at com.google.android.gms.ads.identifier.AdvertisingIdClient.zzb(Unknown Source)
at com.google.android.gms.ads.identifier.AdvertisingIdClient.getAdvertisingIdInfo(Unknown Source)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.facebook.internal.Utility.invokeMethodQuietly(Utility.java:1019)
at com.facebook.internal.AttributionIdentifiers.getAndroidId(AttributionIdentifiers.java:93)
at com.facebook.internal.AttributionIdentifiers.getAttributionIdentifiers(AttributionIdentifiers.java:125)
at com.facebook.appevents.AppEventsLogger.getSessionEventsState(AppEventsLogger.java:795)
at com.facebook.appevents.AppEventsLogger.access$600(AppEventsLogger.java:147)
at com.facebook.appevents.AppEventsLogger$5.run(AppEventsLogger.java:749)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
03-18 06:51:38.299 19336-19336/com.domain.example E/ActivityThread: Activity com.facebook.FacebookActivity has leaked ServiceConnection com.google.android.gms.common.zza@4210df10 that was originally bound here
android.app.ServiceConnectionLeaked: Activity com.facebook.FacebookActivity has leaked ServiceConnection com.google.android.gms.common.zza@4210df10 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:970)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:864)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1786)
at android.app.ContextImpl.bindService(ContextImpl.java:1769)
at android.content.ContextWrapper.bindService(ContextWrapper.java:536)
at com.google.android.gms.common.stats.zzb.zza(Unknown Source)
at com.google.android.gms.common.stats.zzb.zza(Unknown Source)
at com.google.android.gms.ads.identifier.AdvertisingIdClient.zzp(Unknown Source)
at com.google.android.gms.ads.identifier.AdvertisingIdClient.zzb(Unknown Source)
at com.google.android.gms.ads.identifier.AdvertisingIdClient.getAdvertisingIdInfo(Unknown Source)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.facebook.internal.Utility.invokeMethodQuietly(Utility.java:1019)
at com.facebook.internal.AttributionIdentifiers.getAndroidId(AttributionIdentifiers.java:93)
at com.facebook.internal.AttributionIdentifiers.getAttributionIdentifiers(AttributionIdentifiers.java:125)
at com.facebook.appevents.AppEventsLogger.getSessionEventsState(AppEventsLogger.java:795)
at com.facebook.appevents.AppEventsLogger.access$600(AppEventsLogger.java:147)
at com.facebook.appevents.AppEventsLogger$5.run(AppEventsLogger.java:749)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
如果我删除gcm
代码并删除应用并再次安装,则可以正常使用。
我尝试在MainActivity
上进行调试,但我不能。我不知道根本原因是什么以及如何找出问题。
答案 0 :(得分:0)
错误消息基本上意味着某个组件创建了绑定到'service'并且在组件被销毁之前没有从服务解除绑定。
在onHandleIntent()完成后,Android运行时会破坏'IntentService',并且不再有排队的Intent请求。您可以通过添加&#39; onDestroy()&#39;来确认这一点。您的IntentService的方法,其中包含一个日志,以显示何时调用它。
如果在此服务仍在运行的情况下销毁您的应用,则该服务不再具有目的。它将存在于内存消耗资源中,但什么都不做。通过在完成后解除绑定或停止服务,您可以返回这些资源,以便其他应用程序可以使用它们。
这是一个相关的stack overflow ticket,它讨论了活动泄漏其服务连接。