When the screen changes to a horizontal screen, the system will call the OnCreate method of the current Activity again. You can put the following method in your OnCreate to check the current direction, then, let your SetContentView load different Layout xml.
Copy codeThe Code is 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 ");
}
About screen Switching
First, add the configuration in androidmanifest. xml.
Android: configChanges = "orientation | keyboardHidden | navigation
In this way, the. Activity in the program will not repeatedly call onCreate ()
It does not even call onPause. onResume.
Only one onConfigurationChanged (Configuration newConfig) is called)
This is only when XML is added with configuration options.
If the option is added, the onCreate method will be re-activated for the. Activity method mentioned above.
It is better to select the processing mechanism for configuration changes based on your own needs.
4. How does java implement the ping function to determine whether the specified IP address can be connected? The isReachable method of InetAddress can be used:
Copy codeThe Code is as follows: import java.net. InetAddress; public class MainTest {public static void main (String [] args ){
Try {
Int timeOut = 3000;
Byte [] ip = new byte [] {
(Byte) 192, (byte) 168, (byte) 100, (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 ();
}
}
}