程序死亡时以编程方式处理注销BroadcastReceiver [英] Handle programmatically unregister BroadcastReceiver on process death
问题描述
在我的应用中,我以编程方式注册BroadcastReceiver
,并根据应用的业务逻辑在适当的时间取消注册.
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {...}
我想确保当我的应用程序进程意外终止(被杀死)时,接收方是否不会引起内存泄漏?如果这样做,我有什么选择?
我想确保当我的应用程序进程意外终止(被杀死)时,接收方是否不会引起内存泄漏?如果这样做,我有什么选择?
当某个应用程序进程被系统杀死(完全)时,与该进程相关联的所有东西都消失了".应用组件(Activity
,Service
,BroadcastReceiver
)一侧不会发生内存泄漏.
修改
当进程被杀死时ActivityManagerService
使用cleanUpApplicationRecordLocked
方法第15598号)
In my app I register BroadcastReceiver
programmatically like that and unregister it in appropriate time with respect to my app's business logic.
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {...}
I want to make sure that when my app's process unexpectedly die (get killed) no memory leak is caused by the receiver and if it does what are my options?
(Already check the official doc, this great article and this SO thread )
I want to make sure that when my app's process unexpectedly die (get killed) no memory leak is caused by the receiver and if it does what are my options?
When an app process gets killed by the system (quite) everything associated with the process is "gone". No memory leaks from the app component's (Activity
, Service
, BroadcastReceiver
) side can be expected.
Edit
When process get killed ActivityManagerService
clean all app resources using cleanUpApplicationRecordLocked
method here.
You can clearly see that all resources including all registered broadcast receivers being cleaned.(Ln. 15598)
这篇关于程序死亡时以编程方式处理注销BroadcastReceiver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!