Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何根据您在上一个活动中所做的操作显示另一个活动的对话框_Java_Android_Android Alertdialog - Fatal编程技术网

Java 如何根据您在上一个活动中所做的操作显示另一个活动的对话框

Java 如何根据您在上一个活动中所做的操作显示另一个活动的对话框,java,android,android-alertdialog,Java,Android,Android Alertdialog,我想有一个注册页面和创建帐户页面。在“创建帐户”页面中填写完您的信息后,我想返回注册页面,并显示“帐户创建成功”或“代码重新发送”对话框 现在,我正在检查Web服务器的响应,根据状态,它应该显示一个对话框,然后关闭创建帐户活动,在后台显示注册页面,同时弹出对话框,告诉您您的帐户已创建或代码已重新发送 然而,到目前为止,它所做的只是在不显示对话框的情况下关闭我的活动。我假设我必须打开注册页面上的对话框,但我不知道如何询问它是“创建”还是“重新发送”。如果您能根据我所说的内容给我一些关于如何显示适当

我想有一个注册页面和创建帐户页面。在“创建帐户”页面中填写完您的信息后,我想返回注册页面,并显示“帐户创建成功”或“代码重新发送”对话框

现在,我正在检查Web服务器的响应,根据状态,它应该显示一个对话框,然后关闭创建帐户活动,在后台显示注册页面,同时弹出对话框,告诉您您的帐户已创建或代码已重新发送

然而,到目前为止,它所做的只是在不显示对话框的情况下关闭我的活动。我假设我必须打开注册页面上的对话框,但我不知道如何询问它是“创建”还是“重新发送”。如果您能根据我所说的内容给我一些关于如何显示适当对话框的提示,我将非常感激

多谢各位

这是我的密码 注:填写完信息后,按下按钮

public void btnCreate(View v) throws Exception {
    // if we get to here we can send the information to the webserver

    String response = makeRequest(email.getText().toString(), fName
            .getText().toString(), lName.getText().toString());
    if (response != null) {
        org.json.JSONObject obj = new org.json.JSONObject(response);
          //response is created make created dialog
        if ("Created".equals(obj.getString("status"))) {
            new AlertDialog.Builder(CreateAccount.this)
                    .setTitle("Account Creation Successful")
                    .setMessage(
                            "An activation code has been sent to you. Please check your SPAM folder if you do not receive your activation code email")
                    .setNeutralButton("OK", null).show();
         // response is resend and sends the resend dialog
        } else if ("Resend".equals(obj.getString("status"))) {
            new AlertDialog.Builder(CreateAccount.this)
                    .setTitle("Code Resent")
                    .setMessage(
                            "Your activation code has been resent to your email.\n\nIf you are not receiving your activation code, our email is being blocked. Please email us at 'help@iphone-tracker.net' and we will manually send you a code.")
                    .setNeutralButton("OK", null).show();
        }
    }
      //finishes this activity and shows the registration activity (the one before create account)
    finish();

}

在AlertDialog builder的setNeutralButton中,设置一个DialogInterface.onClickListener并在那里执行启动单个活动的逻辑。

正如您所说,您可能应该在下一个活动中创建对话框。启动新活动时,您可以向该活动传递额外信息

所以做一些类似于:

Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
i.putExtra("login_successful", true); // Only true if they logged in.
startActivity(myIntent);
然后,在新活动中,您只需通过检索创建新活动时收到的包(onCreate(bundle savedInstance))来检索从早期活动发送的额外信息

当然,您也可以将字符串和其他基本类型放入捆绑包中


顺便说一句,你不需要“完成”你当前的活动来显示下一个活动-我在想如果用户想注销或以另一个用户的身份登录该怎么办?当您对某个活动调用finish方法时,它将从活动堆栈中删除,并且在您完全重新启动应用程序之前无法检索。

在我看来,您似乎希望您的注册成为ActivityForResult并返回结果。根据结果,调用活动可以显示不同的信息(结果的功能与意图一样,因此也可以将信息打包在其中)

工作得很好,我假设这就是您通常将数据从一个活动传输到另一个活动的方式。
savedInstanceState = this.getIntent().getExtras();
boolean yes = savedInstanceState.getBoolean("login_successful");