in my app I have 2 BroadcastReceivers
. Lets call the AReceiver
and BReceiver
. AReceiver
is just listening for android.intent.action.BOOT_COMPLETED
so it can register BReceiver
for a different action, if its turned on in the settings of my app.
So I have a PreferenceActivity
that can switch the status of my app, which means:
AReceiver
will not register BReceiver
at bootBReceiver
AReceiver
will register BReceiver
at bootBReceiver
Here is the problem I'm having. How can I unregister BReceiver
if it was either registered in AReceiver
or in the PreferenceActivity
, which could have been closed in the meanwhile? I don't know what I have to pass to unregisterBroadcastReceiver()
as an argument, since it wants the instance of the registered receiver.
How do I retrieve the instance of a registered BroadcastReceiver
so I can unregister it?
You should be able to put the BReceiver in the manifest (default disabled) and then enable and disable it at any time. Have a look here