When we use Android for development,The oncreate method is triggered when the activity is switched to the background or the layout is switched from landscape to portrait.
This can be avoided in Android development. We can use androidmanifest. adding the activit element in XML to this attribute Android: configchanges = "orientation | keyboardhidden" can effectively avoid repeated loading of the oncreat method,
The content of androidmanifest. XML is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. Demo"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<Activity Android: Name = ". demogps"
Android: configchanges = "orientation | keyboardhidden"
Android: Label = "@ string/app_name">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
<Uses-library Android: Name = "com. Google. Android. Maps"/>
</Application>
<Uses-SDK Android: minsdkversion = "7"/>
<Uses-Permission Android: Name = "android. Permission. Internet"> </uses-Permission>
<Uses-Permission Android: Name = "android. Permission. access_coarse_location"> </uses-Permission>
<Uses-Permission Android: Name = "android. Permission. access_fine_location"> </uses-Permission>
</Manifest>
At the same time, the onconfigurationchanged (configuration newconfig) method is reloaded in the Java file of the activity, so that methods such as layout switching or window switching are not reloaded.CodeAs follows:
@ Override
Public void onconfigurationchanged (configuration newconfig)
{
Super. onconfigurationchanged (newconfig );
If (this. getresources (). getconfiguration (). Orientation = configuration. orientation_landscape)
{
// Land
}
Else if (this. getresources (). getconfiguration (). Orientation = configuration. orientation_portrait)
{
// Port
}
}