【问题标题】:Show Dialog after startActivity [closed]startActivity 后显示对话框 [关闭]
【发布时间】:2012-05-25 07:06:46
【问题描述】:

在我的应用程序中,用户通过向startActivity()发送特定意图来点击一个按钮以返回主屏幕

但我想在用户进入主屏幕后显示一个对话框(由 AlertDialogBu​​ilder 构建)。进入主屏幕后,我会打电话给finish()。我该怎么做?

或者更一般地说,我如何在调用 startActivity 后显示对话框以启动不属于我的活动(现在是主屏幕)。

【问题讨论】:

  • 您正在调用一些活动。在开始活动的oncreate() 只需创建AlertDialog.Builder
  • 你的问题我不清楚,你想知道如何使用alertDialogBu​​ilder,那么我想我可以帮助你
  • 但是这个活动不是我的……回家吧
  • 你想在主屏幕上显示警报对话框吗??从您的活动中调用完成()之后。我是对的??

标签: android android-dialog


【解决方案1】:

请看这里

PopUp dialog Android from background thread

根据链接

使用通知系统——不要使用对话框代替通知

如果您的后台服务需要通知用户,请使用标准通知系统——不要使用对话框或 toast 来通知他们。对话或吐司会立即获得焦点并打断用户,将注意力从他们正在做的事情上转移开:用户可能在对话出现的那一刻正在输入文本,并且可能意外地对对话进行操作。用户习惯于处理通知,可以在方便时拉下通知栏来回复您的消息。

What are Android dialog notifications? 创建通知的指南在这里:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

【讨论】:

    【解决方案2】:

    如果你需要显示对话框,为什么不写代码在 oncreate() 之后的第一行显示对话框。如果你只希望在按下后退按钮返回屏幕后显示对话框,创建一个变量,当按下后退按钮时,分配一个特定的值。在 oncreate 中,给出一个 if 条件来检查该特定条件是否满足。如果满足,则在 if 块中,编写显示对话框的代码。

    希望你知道创建对话框的代码。如果不知道,请告诉我。我会给你代码

    【讨论】:

      【解决方案3】:

      如果您想在此处显示警报对话框,我将发布其中的一个示例

       private void quitApplication(){
          new AlertDialog.Builder(this)
          .setTitle("Exit")
          .setMessage("Abandon this game?")
          .setIcon(android.R.drawable.ic_dialog_alert)
          .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
                  finish();
              }
          })
          .setNegativeButton("No", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {}
          })
          .show();
      }   
      

      现在你需要做的就是在你的按钮点击事件上调用这个 quitApplication 函数。 希望它可以帮助你。 :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-25
        • 2011-07-10
        • 2018-08-02
        • 1970-01-01
        • 2019-11-16
        • 2016-02-25
        • 1970-01-01
        相关资源
        最近更新 更多