Java 暂停android应用程序,直到提供输入
我已经做了一个应用程序,在开始时,我们要求用户名和安全密码,然后让用户使用该应用程序 目前,我的应用程序在弹出框中一个接一个地询问用户名和安全问题,但应用程序也在后台运行 应用程序正在等待用户输入用户名和安全问题答案,因为post url请求无法获得请求,因为此时未设置“ans1[0]”变量Java 暂停android应用程序,直到提供输入,java,android,sql,servlets,Java,Android,Sql,Servlets,我已经做了一个应用程序,在开始时,我们要求用户名和安全密码,然后让用户使用该应用程序 目前,我的应用程序在弹出框中一个接一个地询问用户名和安全问题,但应用程序也在后台运行 应用程序正在等待用户输入用户名和安全问题答案,因为post url请求无法获得请求,因为此时未设置“ans1[0]”变量 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setConten
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
securityquestion(); // **This part calls the pop up dialog boxes**
statusTxtView = (TextView) findViewById(R.id.status_text);
//Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intentFilter
.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
intentFilter
.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
channel = manager.initialize(this, getMainLooper(), null);
// super.onPause();
startRegistrationAndDiscovery();
//super.onResume();
servicesList = new WiFiDirectServicesList();
getFragmentManager().beginTransaction()
.add(R.id.container_root, servicesList, "services").commit();
}
public void securityquestion(){
final EditText txtUrl = new EditText(this);
final EditText txtUrl2 = new EditText(this);
final String[] ans1 = {""};
final String[] ans2 = {""};
// Set the default text to a link of the Queen
int num = getradomquestionumber();
String messge = "";
if(num==1)
{
txtUrl.setHint("First Pet name");
messge = "What is your first pet name?";
}else{
txtUrl.setHint("Mother's maiden name");
messge = "What is your mother's maiden name?";
}
txtUrl2.setHint("User Name");
new AlertDialog.Builder(this)
.setTitle("Security Question")
.setMessage(messge)
.setView(txtUrl)
.setPositiveButton("Enter", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String url = txtUrl.getText().toString();
ans2[0] = url;
// moustachify(null, url);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
new AlertDialog.Builder(this)
.setTitle("User Name")
.setMessage("Enter UserName")
.setView(txtUrl2)
.setPositiveButton("Enter", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String url = txtUrl.getText().toString();
ans1[0] = url;
// moustachify(null, url);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
HashMap<String , String> postDataParams = new HashMap<String, String>();
postDataParams.put("key", String.valueOf(num));
postDataParams.put("key2", ans1[0]);
response = performPostCall("http://10.19.23.2/NEWS/SecurityQuestion.php", postDataParams);
System.out.println("response -------------- "+response);
if(response == ans2[0]){
}else{
System.exit(0);
}
}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
securityquestion();//**此部分调用弹出对话框**
statusTxtView=(TextView)findViewById(R.id.status\u text);
//setDefaultUncaughtExceptionHandler(新的ExceptionHandler(this));
intentFilter.addAction(WifiP2pManager.WIFI\u P2P\u STATE\u CHANGED\u ACTION);
intentFilter.addAction(WifiP2pManager.WIFI\u P2P\u PEERS\u CHANGED\u ACTION);
意向过滤器
.addAction(WifiP2pManager.WIFI\u P2P\u连接\u更改\u操作);
意向过滤器
.addAction(WifiP2pManager.WIFI\u P2P\u此设备\u更改\u操作);
manager=(WifiP2pManager)getSystemService(Context.WIFI\u P2P\u服务);
channel=manager.initialize(this,getMainLooper(),null);
//super.onPause();
startRegistrationAndDiscovery();
//super.onResume();
servicesList=newwifidirectserviceslist();
getFragmentManager().beginTransaction()
.add(R.id.container_root,servicesList,“services”).commit();
}
公共安全问题{
最终编辑文本txtUrl=新编辑文本(本);
最终编辑文本txtUrl2=新编辑文本(本);
最后一个字符串[]ans1={”“};
最后一个字符串[]ans2={”“};
//将默认文本设置为女王的链接
int num=getRadomQuestionNumber();
字符串messge=“”;
如果(num==1)
{
txtUrl.setHint(“第一个宠物名”);
messge=“你的第一个宠物名是什么?”;
}否则{
txtUrl.setHint(“母亲的娘家姓”);
messge=“你母亲的婚前姓是什么?”;
}
txtUrl2.setHint(“用户名”);
新建AlertDialog.Builder(此)
.setTitle(“安全问题”)
.setMessage(消息)
.setView(txtrl)
.setPositiveButton(“回车”,新的DialogInterface.OnClickListener(){
public void onClick(对话框接口对话框,int whichButton){
字符串url=txtUrl.getText().toString();
ans2[0]=url;
//moutachify(null,url);
}
})
.setNegativeButton(“取消”,新建DialogInterface.OnClickListener()){
public void onClick(对话框接口对话框,int whichButton){
}
})
.show();
新建AlertDialog.Builder(此)
.setTitle(“用户名”)
.setMessage(“输入用户名”)
.setView(TxTRL2)
.setPositiveButton(“回车”,新的DialogInterface.OnClickListener(){
public void onClick(对话框接口对话框,int whichButton){
字符串url=txtUrl.getText().toString();
ans1[0]=url;
//moutachify(null,url);
}
})
.setNegativeButton(“取消”,新建DialogInterface.OnClickListener()){
public void onClick(对话框接口对话框,int whichButton){
}
})
.show();
HashMap postDataParams=新HashMap();
postDataParams.put(“key”,String.valueOf(num));
postDataParams.put(“键2”,ans1[0]);
响应=performPostCall(“http://10.19.23.2/NEWS/SecurityQuestion.php“,postDataParams);
System.out.println(“响应-----------------”+响应);
如果(响应==ans2[0]){
}否则{
系统出口(0);
}
}
目前我无法从服务器获得响应,因为应用程序没有等待用户的响应。如何暂停应用程序,使对话框首先出现,接受用户输入,然后在验证后继续,仅继续应用程序
请您帮助我提出您的建议。您需要这样做:
此外,执行代码不应该在onCreate()中执行,而应该在onStart()中执行,然后在服务器返回肯定答案时执行。有关这些真正基本的内容,请参见。您需要执行以下操作:
public void securityquestion(){
final EditText txtUrl = new EditText(this);
final EditText txtUrl2 = new EditText(this);
final String[] ans1 = {""};
final String[] ans2 = {""};
// Set the default text to a link of the Queen
final int num = getradomquestionumber();
String messge = "";
if(num==1)
{
txtUrl.setHint("First Pet name");
messge = "What is your first pet name?";
}else{
txtUrl.setHint("Mother's maiden name");
messge = "What is your mother's maiden name?";
}
txtUrl2.setHint("User Name");
new AlertDialog.Builder(LoginActivity.this)
.setTitle("User Name")
.setMessage("Enter UserName")
.setView(txtUrl2)
.setPositiveButton("Enter", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String url = txtUrl2.getText().toString();
ans1[0] = url;
// moustachify(null, url);
//ask question and get result
new AlertDialog.Builder(LoginActivity.this)
.setTitle("Security Question")
.setMessage(messge)
.setView(txtUrl)
.setPositiveButton("Enter", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String url = txtUrl.getText().toString();
ans2[0] = url;
// moustachify(null, url);
//Now call or make server request
HashMap<String , String> postDataParams = new HashMap<String, String>();
postDataParams.put("key", String.valueOf(num));
postDataParams.put("key2", ans1[0]);
response = performPostCall("http://10.19.23.2/NEWS/SecurityQuestion.php", postDataParams);
System.out.println("response -------------- "+response);
if(response == ans2[0]){
}else{
System.exit(0);
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
}