When the screen becomes horizontal, the system will re-call the OnCreate method of the current activity. You can place the following method in your OnCreate to check the current direction, and then let your SetContentView load different Layout xml.
if (().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
("info", "landscape");
}
else if (().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
("info", "portrait");
}
About the screen switching
First, you need to add configuration
android:configChanges="orientation|keyboardHidden|navigation
In this way, the activity will not repeatedly call onCreate() in the program
It won't even call.
Only one onConfigurationChanged(Configuration newConfig) will be called
This is under the premise that XML has added configuration options.
If you add the option, as mentioned above, Activity will reactivate the onCreate method
It is better to choose the processing mechanism when configuration changes are selected according to your own needs.
4. How to implement ping function in Java to determine whether the specified IP address can be connected. You can use the isReachable method of InetAddress:
import ;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 = (ip);
for (int i = 0; i < retry; i++) {
if ((timeOut)) {
(i + " OK"); }
else {
(i + " LOSS");
}
}
}
catch (Exception e) {
();
}
}
}