Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Robin Damsgaard Larsen13,929 Points
Declaring BroadcastReceivers in the manifest is deprecated
As per the provided link in the teacher's notes, https://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html#MonitorChanges declaring BroadcastReceivers in the manifest is deprecated from Android 7.0 and up. From what I gather, this is in an effort to lower battery consumption.
What I did to receive the broadcast instead was to register the broadcast receiver in MainActivity's onCreate method:
IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
this.registerReceiver(new NetworkConnectionReceiver(), intentFilter);
Registering a Broadcast Receiver in code is what the next video after the coding challenge is about, and it is shown in which lifecycle methods it's best to un/register Broadcast Receivers (unlike what I did in my code above).
Tonnie FanadezUX Design Techdegree Graduate 22,796 Points
I noted some manifest-declared receivers work just fine when declared on the manifest e.g. android.intent.action.AIRPLANE_MODE.
However, these receivers have to be registered dynamically inside the code for them to work: *android.intent.action.SCREEN_ON *android.intent.action.SCREEN_OFF *android.intent.action.HEADSET_PLUG *android.intent.action.TIME_TICK *android.net.conn.CONNECTIVITY_CHANGE (ConnectivityManager.CONNECTIVITY_ACTION) *android.intent.action.CONFIGURATION_CHANGED