Android onCreate中的AlertDialog

Android onCreate中的AlertDialog,android,android-alertdialog,oncreate,Android,Android Alertdialog,Oncreate,我在onCreate方法中创建了一个AlertDialog。我希望它只在类的第一次发布时显示。但问题是,当我改变设备的方向时,它会显示出来。 由于应用程序的体系结构,我无法使用android:configChanges。 当我更改方向时,是否有其他解决方案不显示AlertDialog? 多谢各位 下面是我如何在onCreate上创建我的AlertDialog 只需添加这个android:configChanges=“orientation | screenSize”在你声明你的MyActivit

我在onCreate方法中创建了一个AlertDialog。我希望它只在类的第一次发布时显示。但问题是,当我改变设备的方向时,它会显示出来。 由于应用程序的体系结构,我无法使用android:configChanges。 当我更改方向时,是否有其他解决方案不显示AlertDialog? 多谢各位

下面是我如何在onCreate上创建我的AlertDialog


只需添加这个
android:configChanges=“orientation | screenSize”
在你声明你的
MyActivity

的清单文件中,你能显示你的代码吗?这是第一次在应用上使用还是每次启动应用时只使用一次?每次启动应用时,我想你应该使用静态变量或SharedReference来存储值,比如
布尔值来检查你的对话框是否已显示..在onCreate()中检查此变量并根据其显示您可以从不同的位置调用此活动吗?如果没有,您可能希望使用一个var来存储对话框是否已显示,并使用onSaveInstance方法保留该var。
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();
    }
}