Android oncreate method is called twice.

Source: Internet
Author: User

Cause:

 

1. Horizontal and vertical screen Rotation

2. After the system is started, find the available mobile network

The oncreate method is triggered. After the application is enabled, the current activity is destroyed in the preceding two cases, and a new activity instance is restarted.

Solution:

1. Add the following settings in androidmanifest. xml.

android:configChanges="mcc|mnc|orientation|keyboardHidden"

2. Reload the following method

@ Override public void onconfigurationchanged (configuration newconfig) {super. onconfigurationchanged (newconfig); // the orientation of the detection screen: vertical or horizontal if (this. getresources (). getconfiguration (). orientation = configuration. orientation_landscape) {// The current screen is a landscape, add additional processing code here} else if (this. getresources (). getconfiguration (). orientation = configuration. orientation_portrait) {// currently the portrait screen, add additional processing code here} // detect the status of the real keyboard: Roll out or close if (newconfig. hardkeyboardhidden = configuration. hardkeyboardhidden_no) {// The physical keyboard is being pushed out, and additional processing code is added here} else if (newconfig. hardkeyboardhidden = configuration. hardkeyboardhidden_yes) {// when the keyboard is closed, add additional processing code here }}

Reference:

Http://www.cnblogs.com/hibraincol/archive/2010/09/18/1829862.html

Http://www.linuxidc.com/Linux/2012-01/50845.htm

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.