1

In Android, I have a receiver class (MyLocalBroadcastReceiver), and I have another activity (MyActivity) which does, LocalBroadcastManager.getInstance(Context).registerReceiver(MyLocalBroadcastReceiver, intentFilter).

Now in some case, consider that MyActivity gets destroyed or it is finished. what happens if the registered receiver is fired? will it still continue to receive the broadcasted intent or since the activity died/finished/destroyed MyLocalBroadcastReceiver will be unregistered too?

Maheshwar Ligade
  • 6,709
  • 4
  • 42
  • 59
Pradheep
  • 139
  • 11
  • 1
    receiver will close too . See this link http://stackoverflow.com/questions/16824341/keep-broadcast-receiver-running-after-application-is-closed – Vivek Mishra Apr 12 '16 at 10:38

1 Answers1

1

Your BroadcastManager will hold the reference to your receiver until you'll call unregisterReceiver and it may cause exception if activity is destroyed and BroadcastManager is trying to Broadcast some intent, you should explicitly call LocalBroadcastManager.getInstance(Context).unregisterReceiver(MyLocalBroadcastReceiver, intentFilter) preferably on onPause in your activity.

Shashank
  • 1,087
  • 1
  • 14
  • 26