Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. class AuthenticatorTask extends AsyncTask<Void, Void, Integer> {
  2.         String username;
  3.         String password;
  4.         Exception ex = null;
  5.  
  6.         @Override
  7.         protected void onPreExecute() {
  8.             super.onPreExecute();
  9.             EditText usernameField = (EditText) findViewById(R.id.edit_text_username);
  10.             EditText passwordField = (EditText) findViewById(R.id.edit_text_password);
  11.             username = usernameField.getText().toString();
  12.             password = passwordField.getText().toString();
  13.         }
  14.  
  15.         @Override
  16.         protected Integer doInBackground(Void... voids) {
  17.             try {
  18.                 Authenticator auth = new Authenticator();
  19.                 return auth.getUserId(username, password);
  20.             } catch (IOException e1) {
  21.                 ex = e1;
  22.             }
  23.         }
  24.  
  25.         @Override
  26.         protected void onPostExecute(Integer userId) {
  27.             super.onPostExecute(userId);
  28.  
  29.             if (ex != null) {
  30.                 Toast.makeText(SignInActivity.this, "Error: Could not access server!", Toast.LENGTH_SHORT).show();
  31.                 return;
  32.             }
  33.  
  34.             if (userId == -1) {
  35.                 Toast.makeText(SignInActivity.this, "Invalid username or password", Toast.LENGTH_SHORT).show();
  36.             } else {
  37.                 startActivity(new Intent(SignInActivity.this, DashboardActivity.class));
  38.             }
  39.  
  40.         }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement