我在 onCreate 方法中创建 AlertDialog 。我希望它只在第一次启动时显示。但问题是当我改变设备的方向时它会显示。 由于应用程序的体系结构,我无法使用 android:configChanges 。 当我更改方向时,有没有其他解决方案不显示 AlertDialog ? 谢谢。
以下是我在 onCreate
上创建 AlertDialog 的方法protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.module);
new AlertDialog.Builder(MyActivity.this).setTitle("Activity")
.setMessage("Alert?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do something
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.show();
}
}
答案 0 :(得分:0)
只需在您声明android:configChanges="orientation|screenSize"
MyActivity
即可