I got the right response but still getting errors and its strange.
Where i press the button to go to next activity:
private void setupClickEvent() {
signIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
userName = username.getText().toString();
userPass = password.getText().toString();
if (!userName.isEmpty() || !userPass.isEmpty()) {
accessWebService();
Log.e("after execute: ", String.valueOf(letLogin));
if (letLogin) {
session.createLoginSession(userName, "waiterx@gmail.com");
Intent intent = new Intent(getActivity().getApplicationContext(), UserProfile.class);
startActivity(intent);
getActivity().overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_right);
getActivity().finish();
} else {
Snackbar.with(getActivity().getApplicationContext()).text(getString(R.string.uname_or_password_not_found)).color(Color.parseColor("#3399FF")).show(getActivity());
}
}
}
});
}
private void accessWebService() {
task = new MyInsertDataTask();
task.execute(new String[]{URL});
}
UPDATED JAVA:
private class MyInsertDataTask extends AsyncTask<String, Void, Boolean> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity().getApplicationContext());
pDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDialog.setIndeterminate(true);
pDialog.setMessage(getString(R.string.dialog_rate_data_submit));
pDialog.setCancelable(false);
pDialog.setInverseBackgroundForced(true);
pDialog.show();
}
@Override
protected Boolean doInBackground(String... params) {
nameValuePairs = new ArrayList<>();
nameValuePairs.add(new BasicNameValuePair("user", userName));
nameValuePairs.add(new BasicNameValuePair("pass", userPass));
try
{
httpClient = new DefaultHttpClient();
httpPost = new HttpPost(params[0]);
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpClient.execute(httpPost);
httpEntity = response.getEntity();
is = httpEntity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuilder result = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
result.append(line);
}
Log.e("HTTP response: ", result.toString());
if (result != null){
data = new JSONObject(result.toString());
isRegistered = data.getBoolean("res");}
Log.e("isRegistered: ", String.valueOf(isRegistered));
}
catch(Exception e)
{
Log.e("Fail 1", e.toString());
}
return isRegistered;
}
@Override
protected void onPostExecute(Boolean aVoid) {
super.onPostExecute(aVoid);
pDialog.dismiss();
}
}
And still does not logging me in!!!!
The logcat output:
09-23 04:36:48.627 22163-22163/com.order.app.order E/after execute:﹕ false
09-23 04:36:48.659 22163-22182/com.order.app.order W/EGL_emulation﹕ eglSurfaceAttrib not implemented
09-23 04:36:48.659 22163-22182/com.order.app.order W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xabc9aa60, error=EGL_SUCCESS
09-23 04:36:51.240 22163-22188/com.order.app.order E/HTTP response:﹕ {"res":true}
09-23 04:36:51.240 22163-22188/com.order.app.order E/isRegistered:﹕ true
09-23 04:36:53.777 22163-22163/com.order.app.order E/after execute:﹕ true
09-23 04:36:53.812 22163-22182/com.order.app.order W/EGL_emulation﹕ eglSurfaceAttrib not implemented
09-23 04:36:53.812 22163-22182/com.order.app.order W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa1d555c0, error=EGL_SUCCESS
09-23 04:36:53.815 22163-22185/com.order.app.order E/HTTP response:﹕ {"res":true}
09-23 04:36:53.815 22163-22185/com.order.app.order E/isRegistered:﹕ true
Since the responce is true and i give isRegistered
the value from the data object why is it still troubles me? The First time i click the button the letLogin variable is false and the Second time is true. How is this possible? Anyone would be able to help me appreciate it!!!