I have made an application where in the starting we ask for username and security password and then let the user use the application.
Currently, my application asks for username and security question one after the other in a pop out box but in the background the application also runs.
The application is waiting for the user to enter the username and security question answer because of which post url request fails to get a request because by that time "ans1[0]" variable is not set.
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);
}
}
Currently I am unable to get a response from the server because the application doesn't wait for the response from the user. How do I pause the application so that fir the dialog box appears first, takes users input and then further after authentication, only continue the application.
Requesting you to please help me with your suggestions.