0

我在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();
    }
}
4

1 回答 1

0

只需将其添加android:configChanges="orientation|screenSize"到您声明的清单文件中MyActivity

于 2013-10-02T13:37:39.317 回答