Advertisement
Guest User

Untitled

a guest
May 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. class AttemptLogin extends AsyncTask<String, String, String> {
  2. /**
  3. * Before starting background thread Show Progress Dialog
  4. * */
  5. boolean failure = false;
  6. @Override
  7. protected void onPreExecute() {
  8. super.onPreExecute();
  9. pDialog = new ProgressDialog(Login.this);
  10. pDialog.setMessage("Attempting login...");
  11. pDialog.setIndeterminate(false);
  12. pDialog.setCancelable(true);
  13. pDialog.show();
  14. }
  15.  
  16. @Override
  17. protected String doInBackground(String... args) {
  18. // TODO Auto-generated method stub
  19. // Check for success tag
  20. int success;
  21. String username = user.getText().toString();
  22. String password = pass.getText().toString();
  23. try {
  24. // Building Parameters
  25. List<NameValuePair> params = new ArrayList<NameValuePair>();
  26. params.add(new BasicNameValuePair("username", username));
  27. params.add(new BasicNameValuePair("password", password));
  28. Log.d("request!", "starting");
  29. // getting product details by making HTTP request
  30. JSONObject json = jsonParser.makeHttpRequest(
  31. LOGIN_URL, "POST", params);
  32. // check your log for json response
  33. Log.d("Login attempt", json.toString());
  34. // json success tag
  35. success = json.getInt(TAG_SUCCESS);
  36. if (success == 1) {
  37. Log.d("Login Successful!", json.toString());
  38. Intent in = new Intent(Login.this, siswa.class);
  39. session.createLoginSession(username);
  40. finish();
  41. startActivity(in);
  42. return json.getString(TAG_MESSAGE);
  43. }else{
  44. Log.d("Login Failure!", json.getString(TAG_MESSAGE));
  45. return json.getString(TAG_MESSAGE);
  46. }
  47. } catch (JSONException e) {
  48. e.printStackTrace();
  49. }
  50. return null;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement