Android unregisters broadcast receiver on next app download
I have a feeling that I already know the answer to this question, but I'm not sure. I'm using a broadcast receiver to intercept incoming SMS messages.
I am registering the receiver in the normal way using the registerReceiver function and when you unregister the receiver you use the unregisterReceiver function. I am storing a global broadcast variable to load and unload the receiver as needed.
If the app closes, as the user actually closes the app, and I don't deregister the recipient in the onDestroy method, which I know is bad practice, would there be a way to deregister the recipient the next time the app loads? Can I create another instance of this broadcast receiver and then discard it?
source to share
If the application closes
You can tell if your UI is in the foreground or not. And you can tell that your application process is in the foreground, in the background, or completed.
It is unclear what "closure" equates to.
how the user actually closes the app
The user can move the user interface of the application and render it in the background (for example, press HOME). The user can destroy the application's UI and move its process to the background (for example, press BACK from the last current activity). The user can end the background process of the application (for example, swipe the application from the list of recent tasks). The user can force stop the application (for example, by pressing the Force Stop button for the application in the settings).
It is unclear what "the user actually closes the application" equates to.
will there be a way to unregister the recipient the next time I download the app?
Either you have a link to your object
or you don't. If you do, call
, passing in that instance
. If you do not have a copy
, you cannot deregister the recipient. If your process was completed between you when you registered a receiver and now that receiver is gone and is not actually registered.
source to share