When the screen changes to a horizontal screen, the system will call back the current Activity OnCreate method, you can put the following methods in your oncreate to check the current direction, and then let your setcontentview to load different layout XML.
Copy Code code as follows:
if (This.getresources (). GetConfiguration (). Orientation = = Configuration.orientation_landscape) {
LOG.I ("info", "landscape");
}
else if (this.getresources (). GetConfiguration (). Orientation = = configuration.orientation_portrait) {
LOG.I ("Info", "Portrait");
}
When it comes to screen switching
First you need to add the configuration in the Androidmanifest.xml
Android:configchanges= "Orientation|keyboardhidden|navigation
This is in the program. The activity will not repeat the call OnCreate ()
does not even call Onpause.onresume.
Only one onconfigurationchanged (Configuration newconfig) will be invoked
This is in the context of XML adding configuration options.
If you are on the premise of adding an option. As mentioned above. The activity will reactivate the OnCreate method
It is better to choose the processing mechanism of the configuration change according to your own requirements.
How to implement the ping function of Java to determine whether the specified IP address can be connected with the InetAddress Isreachable method:
Copy Code code as follows:
Import Java.net.inetaddress;public class Maintest {public static void main (string[] args) {
try {
int timeOut = 3000;
byte[] IP = new byte[] {
(byte), (Byte), (Byte), (byte) 151};
int retry = 4; InetAddress address = inetaddress.getbyaddress (IP);
for (int i = 0; i < retry; i++) {
if (address.isreachable (TimeOut)) {
SYSTEM.OUT.PRINTLN (i + "OK"); }
else {
SYSTEM.OUT.PRINTLN (i + "LOSS");
}
}
}
catch (Exception e) {
E.printstacktrace ();
}
}
}