如何根据您在上一个活动中所做的操作在另一个活动上显示对话框
我想要一个注册页面和创建帐户页面。在创建帐户页面填写信息后,我想返回注册页面,并显示帐户创建成功或代码重新发送的对话框。
截至目前,我正在检查网络服务器的响应,根据状态,它应该显示一个对话框,然后关闭创建帐户活动,在后台显示注册页面,同时弹出对话框并告诉您帐户已创建或者重新发送代码。
然而,到目前为止,它所做的只是关闭我的活动而不显示对话框。我假设我必须打开注册页面上的对话框,但我不知道如何询问它是“创建”还是“重新发送”。如果您能给我一些关于如何根据我所说的内容显示适当对话框的提示,我将非常感激。
谢谢
这是我的代码 注意您填写完信息后按下按钮
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 '[email protected]' 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();
}
I want to have a registration page and a create account page. After filling out your information in the create account page I want to go back to the registration page with a dialog box of either account creation successful or code resent.
As of now I am checking the response of the webserver and depending on the status it should show a dialog box then close the create account activity, showing the registration page in the background while the dialog box pops up and tells you that your account is created or the code is resent.
However as of now all it does is close my activity without showing the dialogs. I am assuming I would have to open the dialog on the registration page but I don't know how to ask if it was "created" or "resent". If you could give me some tips on how to show the appropriate dialog based on what I've said I would be very grateful.
Thank you
here is my code
note you press the button after you finish filling out the information
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 '[email protected]' 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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如您提到的那样,您可能应该在下一个活动中创建对话框。开始新活动时,您可以向该活动传递额外信息。
因此,执行以下操作:
然后,在新活动中,您只需检索从早期活动发送的额外信息,方法是检索创建新活动时收到的捆绑包(onCreate(Bundle savingInstance))。
当然,您也可以将字符串和其他基本类型放入包中。
顺便说一句,您不需要“完成”当前活动来显示下一个活动 - 我在想如果用户想要注销或以其他用户身份登录怎么办?当您对某个活动调用 finish 方法时,该活动将从活动堆栈中删除,并且在您完全重新启动应用程序之前无法检索。
As you mention yourself you should probably be creating the dialogboxes in the next activity. When starting a new activity you can pass extra information to the activity.
So doing something like:
Then in you new activity you simply just retrieve the extra info sent from the earlier activity, by retrieving the bundle which was received when the new activity was created (onCreate(Bundle savedInstance)).
Of course you can also put strings and other primitive types in the bundle as well.
Btw, you do not need to "finish" your current activity to show the next activity - I was thinking what if the user wants to log out or log in as another user? When you call the finish method on an activity it is removed from the activity stack and can't be retrieved until you've restarted the app completely.
在 AlertDialog 构建器的 setNeutralButton 中,设置 DialogInterface.onClickListener 并执行在那里启动各个活动的逻辑。
In your AlertDialog builder's setNeutralButton, set an DialogInterface.onClickListener and perform your logic that launches individual activities there.
在我看来,您会希望您的注册成为 ActivityForResult 并返回结果。根据结果,调用 Activity 可以显示不同的信息(结果函数就像意图一样,因此也可以将信息封装在其中)
It sounds to me like you will want your registration to be a ActivityForResult and return a result. Based on the result the calling Activity can display different information (the result functions just like an intent so can have information packaged in it as well)