I asked this question Is onDestroy called only if you explicitly call finish() ?? or are there any exceptions? now in answer I got that
where are the cases where ondestroy() not get called up.
If you crash with an unhandled exception
If your process is terminated in an urgent fashion (e.g., the system needs RAM to process an incoming phone call)
If the user clicks "Force Stop" on your app's screen in Settings
On a few devices, if the user terminates your process using a manufacturer-supplied task manager
Now as for these cases as onDestroy() will not get called so I thought to try onStop()
But as for all above cases even if i will write code in onStop() to unregister the receiver then still it will not get called because of which my receiver will left registered.
So now my question is where can i write my code to unregister the receiver when any of the above four cases will happen.
Also if it is not possible then i guess as for both
onStop()andonDestroy()for these four cases we cannot rely on them to unregister our receiver then why in Android docs it is written to not useonDestroy()even both are equally unreliable ??
Shouldn't they say that both functions should not be used for releasing resources(unregistering receivers).
Solution - According to commonsware answer
In all three of these cases, your process is gone, and therefore your BroadcastReceiver is also gone. There is nothing to unregister.
So as the broadcastreceiver is also gone, so there won't be any need to unregister the receiver, So i think there won't be any problem in all these three cases if i will use onDestroy() to unregister the receivers.
Only for the 1 Case i will try to implement my own top-level uncaught exception handler, as onDestroy() won't be called for that.