如何在启动 Android 应用程序时显示对话框

How to display dialog upon launching Android app

如何在启动 android 应用程序时显示对话框。

这是我的代码:

AlertDialog.Builder swipeAlert;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    swipeAlert = new AlertDialog.Builder(this);
    swipeAlert.setMessage("Swipe to see map");
    swipeAlert.setPositiveButton("OK",null);

但是当我启动 android 应用程序时,没有任何显示。怎么会?

你需要添加

swipeAlert.show();

必须调用show方法才能显示。

最后加上这个

swipeAlert.show();