【问题标题】:The AlertDialog dosen't show when activity start活动开始时不显示 AlertDialog
【发布时间】:2021-02-01 16:20:16
【问题描述】:

这是我第一次在这里寻求帮助。
基本上问题是我想显示一个AlertDialog,然后开始一个有意图的活动。问题是意图开始时没有显示AlertDialog,我不明白为什么。但是如果我删除意图代码,就会出现警报。

if (userImp == null) {
    AlertDialog alert = builder2.create();
    alert.show();
    LAUNCH_ACTIVITY = 0;
    Intent intent = new Intent(User.this, Credenziali.class);
    startActivity(intent);
}

请任何人帮助我。谢谢。

【问题讨论】:

    标签: java android android-intent android-alertdialog


    【解决方案1】:

    AlertDialog 将与当前活动相关。
    因此,如果当前活动消失,AlertDialog 也将被隐藏。 要解决此问题,您需要先显示 AlertDialog,然后捕获关闭事件。

    这里是代码 sn-p。所以你可以试试这个方法。

    if (userImp == null) {
        AlertDialog alert = builder2.create();
        alert.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
               // your code after dissmiss dialog
               LAUNCH_ACTIVITY = 0;
               Intent intent = new Intent(User.this, Credenziali.class);
               startActivity(intent);
            }
        });
        alert.show();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 2011-10-17
      相关资源
      最近更新 更多