Look at the end use:
Log:
Ok, create a new AndroidLibray and start implementing it.
Allow surfing:
First, we need a tool class to monitor the network status.
Create a broadcast in lib, and then register it in the configuration file.
Improve our receiver:
Listening interface:
Manager:
Add an enumeration class:
Ok, a set of normal operations, one of the most common network monitoring classes is completed. Then we try to use comments to make this small framework look more classy.
Perfect custom comments:
Then stroke the train of thought:
Still a fixed trilogy, follow the steps:
1. Improve our registration method first.
Here, I created a method encapsulation class. Simple: Method Manager
The mMethodList here is the list of MethodManager, which is used to store the filtered methods in the MainActivity, that is, the network monitoring methods. The following is the screening of methods:
Let's define a post method to accomplish this task:
It is realized here that we can monitor the change of a certain network state through the parameters above the network monitoring comments. take for example
The above parameters indicate that this method will only respond when WIFI is disconnected and connected. I just want all the prompts to be set to automatic.
Ok, after you finish the logic, do it:
You're done! Run and see the effect!
Project address: /CocoYuki/NetListener
Is a small project of practicing hands, the actual network request can be easily solved through a callback in 7.0.
Weight loss yoga teaching
Yoga action 1: cobra pose
1, prone, hands under shoulders, legs together.
2. Inhale, slow