1

I am working on android for parse.com. I have successfully logged in and signed up with my credentials and data is also uploading in my parse.com tables. Code snippet for login is given below:

loginbutton.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                // Retrieve the text entered from the EditText
                usernametxt = username.getText().toString();
                passwordtxt = password.getText().toString();

                // Send data to Parse.com for verification
                ParseUser.logInInBackground(usernametxt, passwordtxt,
                        new LogInCallback() {
                            public void done(ParseUser user, ParseException e) {
                                if (user != null) {
                                    // If user exist and authenticated, send user to Welcome.class
                                    Intent intent = new Intent(
                                            LoginSignupActivity.this,
                                            Welcome.class);
                                    startActivity(intent);
                                    Toast.makeText(getApplicationContext(),
                                            "Successfully Logged in",
                                            Toast.LENGTH_LONG).show();
                                    finish();
                                } else {
                                    Toast.makeText(
                                            getApplicationContext(),
                                            "No such user exist, please signup",
                                            Toast.LENGTH_LONG).show();
                                }
                            }
                        });
            }
        });

Now i need to get the information of current user, kindly mention me the method or changing which i have to do to get the information of current user.

Thanks in advance!

5 Answers 5

2

Calling things like user.getObjectId(); or user.getString("username"); is how you get information from the ParseObject.

loginbutton.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                // Retrieve the text entered from the EditText
                usernametxt = username.getText().toString();
                passwordtxt = password.getText().toString();

                // Send data to Parse.com for verification
                ParseUser.logInInBackground(usernametxt, passwordtxt,
                        new LogInCallback() {
                            public void done(ParseUser user, ParseException e) {
                                if (user != null) {
                                    // If user exist and authenticated, send user to Welcome.class

                                    String username = user.getString("username");
                                    String userId = user.getObjectId();

                                    Intent intent = new Intent(
                                            LoginSignupActivity.this,
                                            Welcome.class);
                                    startActivity(intent);
                                    Toast.makeText(getApplicationContext(),
                                            "Successfully Logged in",
                                            Toast.LENGTH_LONG).show();
                                    finish();
                                } else {
                                    Toast.makeText(
                                            getApplicationContext(),
                                            "No such user exist, please signup",
                                            Toast.LENGTH_LONG).show();
                                }
                            }
                        });
            }
        });
Sign up to request clarification or add additional context in comments.

1 Comment

Huabe by using user.getString() it is giving me null values and can't return my values from server
2

Once the user is authenticated, open up new activity and you can access current user by using the static method getCurrentUser.

ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
  // do stuff with the user
} else {
  // show the signup or login screen
}

3 Comments

Thanks @Pasang Sherpa for your comment. Now i need to get the information from my current User. How to get user information like the information which i have pass in parse.com server
currentUser.getString('username'); currentUser.getString('firstName');
it is giving me NULL values. Can't return values from server.
1
ParseUser currentUser = ParseUser.getCurrentUser();
            currentUser.getUsername();
            newTable.put("user_name",currentUser );

This is how you can get a user information in your other table (newTable). Let me know if it helps. :)

Comments

1

With this I got the user info.

ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null){
   String email = currentUser.getEmail();
   String username = currentUser.getUsername();
   String objectID = currentUser.getObjectId();
} else {
  Toast.makeText(getApplicationContext(), "the user does not exist!",Toast.LENGTH_SHORT).show();
}

Comments

0
ParseUser currentUser = ParseUser.getCurrentUser();
String currentUserString = String.valueOf(currentUser.getUsername());
newTable.put("user_name",currentUserString);

For some reason I'm not sure about, you need to cast currentUser to String.

1 Comment

Please do not post answers that do not explain what they do, especially on questions that are old. Someone that finds this question will not benefit from your answer in any manner.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.