When should I use unregisterReceiver? In onPause(), onDestroy(), or onStop()?
Note: I need the service to run in the backgroun
From the Android documentation:
You should implement onStop() to release activity resources such as a network connection or to unregister broadcast receivers.
Then, I would follow these pairs (using @StinePike's analogy):
onResume - onPause
onStart - onStop
Because of the Android Lifecycle, and as @w3bshark mentioned:
In post-HoneyComb (3.0+) devices, onStop() is the last guaranteed handler.