为什么在模拟器中切换方向(ctrl + F11)时未调用onConfigurationChanged覆盖方法。
public class HelloSample extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.main);
System.out.println("Change in Orientation");
}
}
manifest.xml中的
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloSample"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
答案 0 :(得分:2)
使用真实设备,模拟器不支持。