Reputation: 2002
I am trying to stop a BroadcastReceiver from showing up once I exit my application. Until now I only made it show a Toast when an App is installed. It works really well, except that if I exit the app the receiver is still active. This is my Receiver code from the AndroidManifest:
<receiver android:name=".MyBrowdcastreceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<data android:scheme="package" />
</intent-filter>
</receiver>
I want to know what should I put in my onDestroy() or onStop() methods from my main Activity that will cause the receiver to stop.
Thanks.
Upvotes: 1
Views: 518
Reputation: 24031
You have registered the receiver in manifest file which will receive notification even if your app is not running.You can do two things to fulfill your need:
You need to register , unregister the receiver programmatically.
You can take boolean which you will set true if the app is running else false. You can use this boolean on BraodcastReceiver's onReceive() method where you need to put check over the boolean and perform your action if the boolean is true.
Upvotes: 2