Handle programmatically unregister BroadcastReceiver on process death

拜拜、爱过 提交于 2019-12-18 09:24:52

问题


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 )


回答1:


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)



来源:https://stackoverflow.com/questions/40261258/handle-programmatically-unregister-broadcastreceiver-on-process-death

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!