Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Adding Users Using Parse.com Logging In

Attempting to use the Built-in android LoginActivity with parse

I am trying to use the built in LoginActivity with parse and I am having troubles querying the user and checking it against mEmail.

the activity is all the same besides the coped code

/**
     * Represents an asynchronous login/registration task used to authenticate
     * the user.
     */
    public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
        @Override
        protected Boolean doInBackground(Void... params) {
            // TODO: attempt authentication against a network service.

            try {
                // Simulate network access.
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                return false;
            }

            ParseUser user = new ParseUser();
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_USER);
            query.whereEqualTo(ParseConstants.KEY_EMAIL, mEmail);
            query.findInBackground(new FindCallback<ParseObject>() {
                @Override
                public void done(List<ParseObject> users, ParseException e) {
                    String[] emails = new String[users.size()];
                    int i = 0;
                    for(ParseObject user : users) {
                        emails[i] = user.getString(ParseConstants.KEY_EMAIL);
                        i++;
                    }
                }
            });

            for (String credential : DUMMY_CREDENTIALS) {
                String[] pieces = credential.split(":");
                if (pieces[0].equals(mEmail)) {
                    // Account exists, return true if the password matches.
                    return pieces[1].equals(mPassword);
                }
            }

            // TODO: register the new account here.
            user.setUsername(mEmail);
            user.setEmail(mEmail);
            user.setPassword(mPassword);

            user.signUpInBackground(new SignUpCallback() {
                public void done(ParseException e) {
                    if (e == null) {
                        // Success!
                    } else {
                        // Oops!
                        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
                    }
                }
            });

            return true;
        }

        @Override
        protected void onPostExecute(final Boolean success) {
            mAuthTask = null;
            showProgress(false);

            if (success) {
                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            } else {
                mPasswordView.setError(getString(R.string.error_incorrect_password));
                mPasswordView.requestFocus();
            }
        }

Am i on the right path? Thank you.

1 Answer

if you are doing a user table use should reference parseuser instead of parseObject see below:

ParseQuery<ParseUser> losingUserQuery = ParseUser.getQuery(); losingUserQuery.whereDoesNotMatchKeyInQuery("hometown", "city", teamQuery);

Let me know how it goes.

Happy Coding,

JMc