I have a simple broadcast receiver that listens in for connectivity changes and if a network is available, it would set a recurring alarm that would start a short-lived service. If there is no network connection, it would disable the recurring alarm:
public class ConnectivityChange extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(getClass().getName(), "Connectivity changed! :/");
MyApplication app = (MyApplication ) context
.getApplicationContext();
if (app.isConnected()) {
// setup repeating alarms, since we are connected.
app.setCurrencyRatesServiceRepeatingAlarm(context);
Log.d(getClass().getName(), "Connected :D");
} else {
// cancel any repeating alarm, since we are NOT connected.
app.unsetCurrencyRatesServiceRepeatingAlarm(context);
Log.d(getClass().getName(), "Not connected :(");
}
}
}
The manifest looks like:
<receiver android:name="ConnectivityChange">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
All of that works just fine.
HOWEVER, this code seem to run even after I reboot the emulator. I'm not asking for BOOT_COMPLETE. I made sure I didn't restore the emulator from a snapshot. Is this expected behavior? I'm not sure where this is documented. I was about to ask for BOOT_COMPLETE when I came across this.
You can register a BOOT_COMPLETED broadcast receiver, which will get control even if RECEIVE_BOOT_COMPLETED is not requested as a permission.
The Bug is already reported here
even you can check this SO thread