Nir Duan Nir Duan - 1 month ago 7
Android Question

Handle programmatically unregister BroadcastReceiver on process death

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 )

Answer

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.