Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
- private final String mUsername;
- private final String mPassword;
- UserLoginTask(String username, String password) {
- mUsername = username;
- mPassword = password;
- }
- @Override
- protected Boolean doInBackground(Void... params) {
- try { // Simulate network access.
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- return false;
- }
- for (String credential : DUMMY_CREDENTIALS) {
- String[] pieces = credential.split(":");
- if (pieces[0].equals(mUsername)) {
- // Account exists, return true if the password matches.
- return pieces[1].equals(mPassword);
- }
- }
- return true;
- }
- @Override
- protected void onPostExecute(final Boolean success) {
- mAuthTask = null;
- showProgress(false);
- if (success) {
- //finish();
- Intent mainpageIntent = new Intent(LoginActivity.this, NavigationActivity.class);
- LoginActivity.this.startActivity(mainpageIntent);
- } else {
- mPasswordView.setError(getString(R.string.error_incorrect_password));
- mPasswordView.requestFocus();
- }
- }
- @Override
- protected void onCancelled() {
- mAuthTask = null;
- showProgress(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement