Android screen and layout issues

Source: Internet
Author: User

Here I did a little test, before I saw something about this, until later I really met the project, the last resort to really familiar with the inside of the process.


Here I put the test source:


Testactivity.java



Package Cn.com.hrmdemo;

Import android.app.Activity;
Import android.content.res.Configuration;
Import Android.os.Bundle;
Import Android.widget.Toast;

public class Testactivity extends Activity {

@Override
protected void OnCreate (Bundle arg0) {
SYSTEM.OUT.PRINTLN ("------testactivity onCreate------");
Toast.maketext (This, "OnCreate ... ", Toast.length_short). Show ();
Super.oncreate (arg0);
Setcontentview (r.layout.test_linearlayout);
}

@Override
protected void Onrestoreinstancestate (Bundle savedinstancestate) {
SYSTEM.OUT.PRINTLN ("------testactivity onrestoreinstancestate------");
Toast.maketext (This, "Onrestoreinstancestate ... ", Toast.length_short). Show ();
TODO auto-generated Method Stub
Super.onrestoreinstancestate (savedinstancestate);
}

@Override
protected void OnStart () {
SYSTEM.OUT.PRINTLN ("------testactivity onStart------");
Toast.maketext (This, "OnStart ... ", Toast.length_short). Show ();
TODO auto-generated Method Stub
Super.onstart ();
}

@Override
protected void Onrestart () {
SYSTEM.OUT.PRINTLN ("------testactivity onrestart------");
Toast.maketext (This, "Onrestart ... ", Toast.length_short). Show ();
TODO auto-generated Method Stub
Super.onrestart ();
}

@Override
protected void Onresume () {
SYSTEM.OUT.PRINTLN ("------testactivity onresume------");
Toast.maketext (This, "Onresume ... ", Toast.length_short). Show ();
TODO auto-generated Method Stub
Super.onresume ();
}

@Override
protected void Onsaveinstancestate (Bundle outstate) {
SYSTEM.OUT.PRINTLN ("------testactivity onsaveinstancestate------");
Toast.maketext (This, "Onsaveinstancestate ... ", Toast.length_short). Show ();
TODO auto-generated Method Stub
Super.onsaveinstancestate (outstate);
}

@Override
protected void OnPause () {
SYSTEM.OUT.PRINTLN ("------testactivity onPause------");
Toast.maketext (This, "OnPause ... ", Toast.length_short). Show ();
TODO auto-generated Method Stub
Super.onpause ();
}

@Override
protected void OnStop () {
SYSTEM.OUT.PRINTLN ("------testactivity onStop------");
Toast.maketext (This, "OnStop ... ", Toast.length_short). Show ();
TODO auto-generated Method Stub
Super.onstop ();
}

@Override
protected void OnDestroy () {
SYSTEM.OUT.PRINTLN ("------testactivity ondestroy------");
Toast.maketext (This, "OnDestroy ... ", Toast.length_short). Show ();
TODO auto-generated Method Stub
Super.ondestroy ();
}

@Override
public void onconfigurationchanged (Configuration newconfig) {
SYSTEM.OUT.PRINTLN ("------testactivity onconfigurationchanged------");
Toast.maketext (this, "screen changed ... ", Toast.length_short). Show ();
TODO auto-generated Method Stub
Super.onconfigurationchanged (Newconfig);
}

}

------------------------------------------------------above is the source----------------------------------------------------------


Let's see how the demo is configured and how it works

This screen configuration is mainly in the Androidmanifest.xml, is the Android App manifest file:

<activity .....

Android:configchanges= "The way you want to configure"

>

In your activity, configure your screen and toggle mode

1). Do nothing to configure the case

A. Under normal circumstances:

07-24 08:43:59.519:i/system.out (18726):------testactivity onCreate------
07-24 08:43:59.609:i/system.out (18726):------testactivity onStart------
07-24 08:43:59.619:i/system.out (18726):------testactivity onresume------


B. In the case of switching the horizontal screen:

07-24 08:51:01.359:i/system.out (18936):------testactivity onPause------
07-24 08:51:01.379:i/system.out (18936):------testactivity onsaveinstancestate------
07-24 08:51:01.389:i/system.out (18936):------testactivity onStop------
07-24 08:51:01.399:i/system.out (18936):------testactivity OnDestroy------
07-24 08:51:01.429:d/memalloc (18936):/dev/pmem:unmapping buffer base:0x5bb4d000 size:4608000 offset:3072000
07-24 08:51:01.429:d/memalloc (18936):/dev/pmem:unmapping buffer base:0x5c8c5000 size:16531456 offset:14995456
07-24 08:51:01.449:i/system.out (18936):------testactivity onCreate------
07-24 08:51:01.579:i/system.out (18936):------testactivity onStart------
07-24 08:51:01.579:i/system.out (18936):------testactivity onrestoreinstancestate------
07-24 08:51:01.599:i/system.out (18936):------testactivity onresume------


C. Then switch back to the vertical screen:

07-24 08:51:42.669:i/system.out (18936):------testactivity onPause------
07-24 08:51:42.689:i/system.out (18936):------testactivity onsaveinstancestate------
07-24 08:51:42.699:i/system.out (18936):------testactivity onStop------
07-24 08:51:42.729:i/system.out (18936):------testactivity OnDestroy------
07-24 08:51:42.759:d/memalloc (18936):/dev/pmem:unmapping buffer base:0x5c8c5000 size:4608000 offset:3072000
07-24 08:51:42.759:d/memalloc (18936):/dev/pmem:unmapping buffer base:0x5cd2a000 size:10797056 offset:9261056
07-24 08:51:42.789:i/system.out (18936):------testactivity onCreate------
07-24 08:51:42.859:i/system.out (18936):------testactivity onStart------
07-24 08:51:42.859:i/system.out (18936):------testactivity onrestoreinstancestate------
07-24 08:51:42.879:i/system.out (18936):------testactivity onresume------


2) Configure android:configchanges= "Orientation|keyboardhidden" (Before 4.0)

A. Under normal circumstances:

07-24 08:54:05.059:i/system.out (18936):------testactivity onCreate------
07-24 08:54:05.199:i/system.out (18936):------testactivity onStart------
07-24 08:54:05.219:i/system.out (18936):------testactivity onresume------


B. In the case of switching the horizontal screen:

07-24 08:54:25.909:i/system.out (18936):------testactivity onPause------
07-24 08:54:25.919:i/system.out (18936):------testactivity onsaveinstancestate------
07-24 08:54:25.929:i/system.out (18936):------testactivity onStop------
07-24 08:54:25.949:i/system.out (18936):------testactivity OnDestroy------
07-24 08:54:25.979:d/memalloc (18936):/dev/pmem:unmapping buffer base:0x5c7c5000 size:19603456 offset:18067456
07-24 08:54:25.979:d/memalloc (18936):/dev/pmem:unmapping buffer base:0x5da77000 size:4608000 offset:3072000
07-24 08:54:26.019:i/system.out (18936):------testactivity onCreate------
07-24 08:54:26.069:i/system.out (18936):------testactivity onStart------
07-24 08:54:26.079:i/system.out (18936):------testactivity onrestoreinstancestate------
07-24 08:54:26.079:i/system.out (18936):------testactivity onresume------


C. Then switch back to the vertical screen:

07-24 08:55:02.099:i/system.out (18936):------testactivity onPause------
07-24 08:55:02.109:i/system.out (18936):------testactivity onsaveinstancestate------
07-24 08:55:02.119:i/system.out (18936):------testactivity onStop------
07-24 08:55:02.129:i/system.out (18936):------testactivity OnDestroy------
07-24 08:55:02.139:d/memalloc (18936):/dev/pmem:unmapping buffer base:0x5c7c5000 size:4608000 offset:3072000
07-24 08:55:02.139:d/memalloc (18936):/dev/pmem:unmapping buffer base:0x5cc30000 size:9216000 offset:7680000
07-24 08:55:02.179:i/system.out (18936):------testactivity onCreate------
07-24 08:55:02.249:i/system.out (18936):------testactivity onStart------
07-24 08:55:02.289:i/system.out (18936):------testactivity onrestoreinstancestate------
07-24 08:55:02.309:i/system.out (18936):------testactivity onresume------


found that the above results are not the same as the online friends, the original is a difference.

Then went to the Internet to search the information found, arrived. 4.0 later. Adding such a configuration would make the activity's life cycle not be called again



3) Configure android:configchanges= "Keyboardhidden|orientation|screensize" (After 4.0)

A. Under normal circumstances:

07-24 08:54:05.059:i/system.out (18936):------testactivity onCreate------
07-24 08:54:05.199:i/system.out (18936):------testactivity onStart------
07-24 08:54:05.219:i/system.out (18936):------testactivity onresume------


B. In the case of switching the horizontal screen:

07-24 09:08:21.639:i/system.out (19533):------testactivity onconfigurationchanged------


C. Then switch back to the vertical screen:

07-24 09:08:21.639:i/system.out (19533):------testactivity onconfigurationchanged------


Summary: It is important to configure the activity to not reload the life cycle when switching between the screen and the


4.0 ago

<activity .....

Android:configchanges= "Orientation|keyboardhidden"

>


After 4.0

<activity .....

Android:configchanges= "Keyboardhidden|orientation|screensize"

>




------------------------------------------------------Common Settings---------------------------------------------------------


1. If your app specifies that you want to display a horizontal screen,

<activity .....

android:screenorientation= "Portrait"

>


2. If your app specifies to display a vertical screen

<activity .....

android:screenorientation= "Landscape"

>











Android screen and layout issues

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.