Android to achieve horizontal screen code and ideas _android

Source: Internet
Author: User
Tags call back

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 ();

}

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.