Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AttemptLogin extends AsyncTask<String, String, String> {
- /**
- * Before starting background thread Show Progress Dialog
- * */
- boolean failure = false;
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- pDialog = new ProgressDialog(Login.this);
- pDialog.setMessage("Attempting login...");
- pDialog.setIndeterminate(false);
- pDialog.setCancelable(true);
- pDialog.show();
- }
- @Override
- protected String doInBackground(String... args) {
- // TODO Auto-generated method stub
- // Check for success tag
- int success;
- String username = user.getText().toString();
- String password = pass.getText().toString();
- try {
- // Building Parameters
- List<NameValuePair> params = new ArrayList<NameValuePair>();
- params.add(new BasicNameValuePair("username", username));
- params.add(new BasicNameValuePair("password", password));
- Log.d("request!", "starting");
- // getting product details by making HTTP request
- JSONObject json = jsonParser.makeHttpRequest(
- LOGIN_URL, "POST", params);
- // check your log for json response
- Log.d("Login attempt", json.toString());
- // json success tag
- success = json.getInt(TAG_SUCCESS);
- if (success == 1) {
- Log.d("Login Successful!", json.toString());
- Intent in = new Intent(Login.this, siswa.class);
- session.createLoginSession(username);
- finish();
- startActivity(in);
- return json.getString(TAG_MESSAGE);
- }else{
- Log.d("Login Failure!", json.getString(TAG_MESSAGE));
- return json.getString(TAG_MESSAGE);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement