When you set the activity's android:configchanges, the screen will recall the various lifecycles
I actually test the discovery settings
android:configchanges= "Keyboardhidden|orientation" or not set
The OnCreate is also executed every time the screen toggles, and does not execute onconfigurationchanged
Set up
Android:configchanges= "Orientation|screensize"
OnCreate is not executed and onconfigurationchanged is executed.
Test code:
public class Mainactivity extends Activity { TextView lbl; @Override protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); LBL = (TextView) Findviewbyid (R.id.label); LOG.D ("123", "onCreate"); } @Override public void onconfigurationchanged (Configuration newconfig) { super.onconfigurationchanged ( Newconfig); if (newconfig.orientation = = configuration.orientation_landscape) { lbl.settext ("horizontal screen"); } else{ Lbl.settext ("vertical screen");}}}
<activity android:name= ". Mainactivity " android:label=" @string/app_name " android:configchanges=" Orientation|screensize "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android: Name= "Android.intent.category.LAUNCHER"/> </intent-filter></activity>
Android:configchanges Property