You cannot call oncreate when converting an android screen.

Source: Internet
Author: User

You cannot call oncreate when converting an android screen.

When the screen of the Android device is automatically rotated horizontally and vertically, the oncreate function will be called again each time for initialization. If the loading data volume is slightly larger, it will take a long time and the user experience is poor, in fact, you can configure the androidmanifest file to change the execution process of the program, so as to avoid multiple calls of the oncreate function during screen rotation.

1. Modify the androidmanifest. xml file and add parameters under the activity Tag:

<Activity Android: Name = "myactivity" </P> <p> Android: configchanges = "orientation | keyboardhidden"> </P> <p>

2. In myactivity, The onconfigurationchanged method is reloaded (automatically called each time the screen is switched) to initialize different Display Interfaces in the horizontal and vertical directions and initialize other data:

@ Override </P> <p> Public void onconfigurationchanged (configuration newconfig) {</P> <p> super. onconfigurationchanged (newconfig); </P> <p>/* </P> <p> If (this. getresources (). getconfiguration (). orientation = configuration. orientation_landscape) {</P> <p> // Add the code to be processed by the landscape </P> <p>} else if (this. getresources (). getconfiguration (). orientation = configuration. orientation_portrait) {</P> <p> // Add the code to be processed by the portrait screen </P> <p >}</P> <p> */</P> <p >}</P> <p>

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.