Questions about the oncreate multiple calls of Android Activity

Source: Internet
Author: User

Today, I used Huawei 8600 to run the project. I suddenly saw that oncreate was executed twice!
How can we tolerate the existence of such a strange thing!

Of course, at the beginning, I found that the project was not going in. After printing, I found that ondestory was automatically called,
That is, the project is automatically exited once oncreate-> onresume-> onpause-> onstop-> ondestory is executed.

I don't want to worry about the trouble. Then I removed ondestory, and I found that although the project can run normally, oncreate has been executed twice!

I found the following information and someone has encountered a similar problem on the Internet. Please refer to http://www.iteye.com/problems/60504 and finally I have fixed this question.

However, gundumw100 does not show the illustration of the androidmanifest. xml file. It looks a little tired, so I will give a detailed solution to help students who encounter the same problem.


, The red part is the modified part.

At this time, the problem of multiple oncreate calls has been fixed, and it is closely related to adding an Android: configchanges = "orientation | keyboardhidden.


Of course, you can also reload onconfigurationchanged in the activity to handle the process when you switch between the horizontal and vertical screens, because after the above Code is added, the screen switching does not call oncreate.


@ Override
Public void onconfigurationchanged (configuration newconfig ){
// Todo auto-generated method stub
If (this. getresources (). getconfiguration (). Orientation = configuration. orientation_landscape ){
System. Out. println ("orientation_landscape ="
+ Configuration. orientation_landscape); // The current screen is landscape

} Else if (this. getresources (). getconfiguration (). Orientation = configuration. orientation_portrait ){
System. Out. println ("orientation_portrait ="
+ Configuration. orientation_portrait); // The current screen is landscape

}
Super. onconfigurationchanged (newconfig );
}

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.