Gps Status Enabled/disabled Broadcast Receiver
Solution 1:
There are two ways of registering broadcast receivers in Android:
- in the code (your case)
- in AndroidManifest.xml
Let me explain the differences.
Case 1 (Broadcast Receiver registered in the code)
You will only receive broadcasts as long as context where you registered your receiver is alive. So when activity or application is killed(depending where you registered your receiver) you won't receive broadcasts anymore.
I guess you registered broadcast receiver in the activity context which is not very good approach. If you want to register broadcast receiver for your application context you can do something like this:
getApplicationContext().registerReceiver(m_gpsChangeReceiver, new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION));
Case 2 (Broadcast Receiver registered in AndroidManifest.xml)
You will receive broadcasts even when your application is killed(system will wake your application up). This is right approach when you want to receive broadcasts no matter if your app is running.
Add this receiver to your AndroidManifest.xml:
<receiverandroid:name="com.yourpackage.NameOfYourBroadcastReceiver"><intent-filter><actionandroid:name="android.location.PROVIDERS_CHANGED" /></intent-filter></receiver>
EDIT: Some special broadcasts (i.e. SCREEN_ON or SCREEN_OFF) must be registered in code (case 1) otherwise they won't be delivered to your application.
Post a Comment for "Gps Status Enabled/disabled Broadcast Receiver"