Huawei G9 Youth Android 6.0 Tests Horizontal and Vertical Screen Switching

Posted by RichterBelmont on Thu, 23 May 2019 03:24:32 +0200

Huawei G9 Youth Android 6.0 Tests Horizontal and Vertical Screen Switching

Some people on the Internet say that horizontal and vertical screen switching is not only related to the android version of mobile phones, but also to targetSdkVersion. So let's test whether it is really related to these two aspects.

1. Mobile phone configuration list:


Model: HUAWEI VNS-AL00
Android version: 6.0

2. build.gradle configuration:

minSdkVersion 19
targetSdkVersion 25

3. Testing:


MainActivity.java code:

package com.example.yds.mylistviewtest;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity {

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("TAG","onStart");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d("TAG","onRestart");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("TAG","onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("TAG","onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("TAG","onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("TAG","onDestroy");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d("TAG","onCreate");

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.d("TAG","onSaveInstanceState");
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        Log.d("TAG","onRestoreInstanceState");
    }
}

1. Do not set android:configChanges in Android Manifest. The results are as follows:
Vertical screen switching horizontal screen:

As you can see, the whole life cycle of Activity goes through once, so how about switching from the horizontal screen to the vertical screen?

As you can see, the results are the same, and the whole life cycle of Activity has passed through.

2. Set android:configChanges="orientation" in Android Manifest. The results are as follows:
Vertical screen to horizontal screen:

As you can see, the whole life cycle of Activity goes through once.
When the horizontal screen is switched to the vertical screen, no Activity life cycle is mobilized!!!

3. Setting up in Android Manifest
android:configChanges="orientation | keyboard Hidden", the results are as follows:
Vertical screen to horizontal screen:

As you can see, the whole life cycle of Activity goes through once.
When the horizontal screen is switched to the vertical screen, no Activity life cycle is mobilized!!!
3. Setting up in Android Manifest
When android:configChanges= "orientation | keyboard Hidden | screenSize", horizontal and vertical screen switching does not change any life cycle of Activity.

Conclusion: In Android version 6.0, without configChanges, the horizontal and vertical screens can only be switched once. Setting configChanges= "orientation" or configChanges= "orientation | keyboard Hidden" vertical screens to switch the horizontal screen will mobilize the activity life cycle once, while the horizontal screen switching vertical screen will not call the activity life cycle. Setting configChanges= "orientation | keyboard Hidden | screenSize" will not invoke the Activity life cycle when the screen is switched horizontally or vertically.

Then set the targetSdkVersion to 19, and the final result is consistent with the above, because we have to review other content, so this test only tests these, and maybe we will do a comprehensive test in the future.

Topics: Android Mobile Gradle Java