I have an Android library that requires a BroadcastReceiver, which I register in an object constructor. It performs actions on that object based on changing internet state. But, I’m encountering error messages about a leaked receiver, because I don’t call unregister.
How and where can I call unregister when I have no information on when the Activity would end? Since I am only providing the class that would be instantiated by an Activity, so no onPause, onClose methods.
You could try saving your receiver in a static. I think only get this error if you register the same receiver twice.
If that fails, you might also try calling context.getApplicationContext().registerBroadcastReceiver() instead of using the activity context.