标签:
设置Activity的android:configChanges时,切屏会重新调用各个生命周期
本人实际测试发现设置
android:configChanges="keyboardHidden|orientation"或不设置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("横屏"); } else{ lbl.setText("竖屏"); } } }
<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>
标签:
原文地址:http://blog.csdn.net/xgbing/article/details/50719492