how to stop BroadcastReceiver if app is closed
I defined in my Manifest a Broadcast Receiver to control if the internet connection is active or no开发者_JAVA百科t. If there is no internet the app starts an Intent and opens a new Activity.
The problem is that if I close the app and I lose the internet connection the Activity pops up!
How do I stop the broadcast receiver when the app is closed?
Thanks
BroadcastReceiver is not closing. He may works even your app is closed. Try to add special boolean statements in your onReceive method.
Sample: if app closed - don't do code in onReceive
onReceive(){
if(isAppRunning){
// do something if app is running
}
}
If you want the broadcast receiver to act only when the activity is running, you might need to consider registering inside the activity.
精彩评论