2

在清单中,我只有活动,接收器上没有任何服务。当我完成活动时,我在 logcat 中看到了这个:

E/ActivityThread: Activity com.example.some.activity has leaked IntentReceiver com.android.internal.policy.impl.PhoneWindow$1@41bbe958 that was originally registered here. Are you missing a call to unregisterReceiver()?
android.app.IntentReceiverLeaked: Activity com.example.some.activity has leaked IntentReceiver com.android.internal.policy.impl.PhoneWindow$1@41bbe958 that was originally registered here. Are you missing a call to unregisterReceiver()?
at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:792)
at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:593)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1127)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1114)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1108)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:365)
at com.android.internal.policy.impl.PhoneWindow.registerBroad(PhoneWindow.java:215)
at com.android.internal.policy.impl.PhoneWindow.<init>(PhoneWindow.java:243)
at com.android.internal.policy.impl.Policy.makeNewWindow(Policy.java:63)
at com.android.internal.policy.PolicyManager.makeNewWindow(PolicyManager.java:59)
at android.app.Activity.attach(Activity.java:4981)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2008)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

因为我很伤心我没有注册任何接收器所以我不知道要取消注册什么

4

1 回答 1

-2

您需要在活动停止时注销您的接收器:

@Override
protected void onStop()
{
    unregisterReceiver(yourReceiver);
    super.onStop();
}

希望这能解决您的问题。

于 2013-06-19T09:21:15.493 回答