Code and ideas for implementing horizontal screen in android

Source: Internet
Author: User

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

}

}

}

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.