I have been trying to work out how to clear a broadcast receiver after it has been used. My app currently has the broadcast receiver registered within the Android Manifest and then I am calling it using an intent , to a PendingIntent and then from there I use an AlarmManager , this then triggers the Broadcast receiver at the specified time,
However I feel that when the time occurs and the broadcast receiver has been processed, it is then left in memory unused.
I have read other posts and articles about unregistering the broadcast receiver from the activity it came from, however the activity it starts from, needs to have the ability to be closed without effecting the broadcast receiver, so if I unregister it at the onPause() part of the activity, surely this will end the broadcast receiver before it has started?
Any help would be appreciated.
Let the system handle it. It will be garbage collected as needed and often is quickly. In addition, the BroadcastReceiver javadoc states that it will be aggressively killed.