gpt4 book ai didi

android - 当我没有注册任何接收者时,Activity 泄露了 IntentReceiver

转载 作者:行者123 更新时间:2023-11-29 14:17:22 25 4
gpt4 key购买 nike

在 list 中,我只有 Activity ,接收器上没有任何服务。当我完成 Activity 时,我在 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)

很遗憾我还没有注册任何接收器所以我不知道要注销什么

最佳答案

您需要在停止 Activity 时注销接收器:

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

希望这能解决您的问题。

关于android - 当我没有注册任何接收者时,Activity 泄露了 IntentReceiver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17187405/

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