Androidmanifest in Activity configurations android: Use configChanges property

1.android:configChanges total value of the property there are several

Android:configChanges=[mcc,mnc,locale,touchscreen,keyboard,keyboardHidden,navigation,screenLayout,

fontScale,uiMode,orientation,screenSize,smallestScreenSize]

 

2. Other background complement the program at run time, some of the configuration of the device may change, such as: switch the screen anyway, when such a thing happens keyboard availability, activity in the absence of configuration android: configChanges restarts when, The procedure is shown below:

Its onPause, onSaveInstanceState, onStop, onDestroy method will be called. onSaveInstanceState method will be before onStop method calls, but he is no specific method calls and onPause order, after the former can be.

OnSaveInstanceState will save some of your data by the method of application before destroying activity, then call onDestroy method, and then when re-creating activity calls onRestoreInstanceState method to restore previously saved data after calling onCreate method

 

3. topic: Use android: configChanges property, the runtime configuration if the changes occur, will not restart activity that is not to go in Scheme 2, but the notification procedure to call onConfigurationChanged function. For example: When you change the screen anyway, the original will re-start activity, but the definition of this property, it will not restart the activity, but rather a function call onConfigrationChanged

Using this attribute may comprise a plurality of attributes, with intermediate | separated

    VALUE DESCRIPTION 
mcc International mobile subscriber identity belongs to the country code is changed, sim is detected, and to update mcc MCC mobile users Country Code
mnc Mobile network international mobile subscriber identity number is changed, sim is detected, and to update mnc MNC is a mobile network number, of up to two digits, a mobile communication network identifies the mobile user belongs
locale Area where the user changes, usually when the user switches the language, the language will be displayed after switching
touchscreen The touch screen is changed ------ usually does not occur
keyboard ---- keyboard changed by the user, for example, external keyboard
keyboardHidden Keyboard usability changed
navigation Navigation changes do not usually occur -----
screenLayout Display screen has changed ------ different display is activated
fontScale Font Scale change ---- chose a different global font
uiMode User mode changes
orientation Change the screen orientation switch the screen anyway ---
screenSize Screen size has changed
smallestScreenSize Changing the physical size of the screen, such as: a connection to an external screen

Need to add is determined as follows when the method of changing the orientation of the screen onConfigurationChanged

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    int orientation = newConfig.orientation;
    if (orientation == Configuration.ORIENTATION_PORTRAIT) {
        // TODO: 18/2/22 vertical screen operation
     }
    else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        // TODO: 18/2/22  横屏操作
    }
}

 

4.最后来个配置AndroidManifest示例如下:在屏幕方向改变时或者键盘可用性发生改变时或者屏幕大小发生变化时调用onConfigurationChanged方法而不重新启动activity

<activity
    android:name="com.mining.cloud.activity.ActivityXXX"
    android:configChanges="orientation|keyboardHidden|screenSize"/>
发布了41 篇原创文章 · 获赞 8 · 访问量 2万+

Guess you like

Origin blog.csdn.net/huma8848888/article/details/95049902
Recommended