public class

AsyncUser

extends User
java.lang.Object
   ↳ java.util.AbstractMap<K, V>
     ↳ com.google.api.client.util.GenericData
       ↳ com.google.api.client.json.GenericJson
         ↳ com.kinvey.java.User
           ↳ com.kinvey.android.AsyncUser

Class Overview

Wraps the com.kinvey.java.User public methods in asynchronous functionality using native Android AsyncTask.

This functionality can be accessed through the user() convenience method.

Methods in this API use either KinveyUserCallback for authentication, login, and user creation, or the general-purpose KinveyClientCallback used for User data retrieval, updating, and management.

Login sample:

 public void submit(View view) {
       kinveyClient.user().login(mEditUserName.getText().toString(), mEditPassword.getText().toString(),
               new KinveyUserCallback() {
           public void onFailure(Throwable t) {
               CharSequence text = "Wrong username or password.";
               Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
           
           public void onSuccess(User u) {
               CharSequence text = "Welcome back," + u.getUserName() + ".";
               Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
               LoginActivity.this.startActivity(new Intent(LoginActivity.this,
                       SessionsActivity.class));
               LoginActivity.this.finish();
           }
       });
   }
 

Saving user data sample:

 User user = kinveyClient.user();
        user.put("fav_food", "bacon");
        user.update(new KinveyClientCallback<User.Update>() {

            public void onFailure(Throwable e) { ... 

            public void onSuccess(User u) { ... }
       });
   }
 

This class is not thread-safe.

Summary

[Expand]
Inherited Constants
From class com.kinvey.java.User
Public Methods
void create(String username, String password, KinveyUserCallback callback)
Asynchronous method to create a new Kinvey User.
void delete(Boolean hardDelete, KinveyUserDeleteCallback callback)
Asynchronous Call to Delete the current user from the Kinvey backend

Constructs an asynchronous request to delete the current Kinvey user.

void keepOfflineStorageOnLogout()
Set a flag to allow local offline storage to persist after calls to logout.
void login(KinveyUserCallback callback)
Asynchronous implicit user login.
void login(String userid, String password, KinveyUserCallback callback)
Asynchronous Kinvey user login.
void loginAuthLink(String accessToken, String refreshToken, KinveyUserCallback callback)
void loginFacebook(String accessToken, KinveyUserCallback callback)
Asynchronous Facebook login.
void loginGoogle(String accessToken, KinveyUserCallback callback)
Asynchronous Google login.
void loginKinveyAuthToken(String userId, String authToken, KinveyUserCallback callback)
Login to Kinvey services using a Kinvey user's _id and their valid Kinvey Auth Token.
void loginLinkedIn(String accessToken, String accessSecret, String consumerKey, String consumerSecret, KinveyUserCallback callback)
Asynchronous Linked In login.
void loginSalesForce(String accessToken, String clientid, String refreshToken, String id, KinveyUserCallback callback)
Login to Kinvey Services using a Salesforce identity
void loginTwitter(String accessToken, String accessSecret, String consumerKey, String consumerSecret, KinveyUserCallback callback)
Asynchronous Twitter login.
User.LogoutRequest logout()
Logs out the current user and clears the local sqllite3 storage
void registerPush()
This method is deprecated. used for UrbanAirship, GCM only requires a call to myClient.push().initialize(...);
void resetPassword(String username, KinveyUserManagementCallback callback)
Asynchronous Call to initiate a Password Reset request

The reset password request initiates a server-side process to reset a user's password.

<T> void retrieve(KinveyClientCallback<T> callback)
Asynchronous Call to Retrieve (refresh) the current user

Constructs an asynchronous request to refresh current user's data via the Kinvey back-end.

<T> void retrieve(Query q, KinveyListCallback<T> callback)
Asynchronous Call to Retrieve users via a Query

Constructs an asynchronous request to retrieve User objects via a Query.

void retrieve(String[] resolves, KinveyUserCallback callback)
Asynchronous call to retrive (refresh) the current user, and resolve KinveyReferences

Constructs an asynchronous request to refresh current user's data via the Kinvey back-end.

void retrieve(Query query, String[] resolves, KinveyUserListCallback callback)
Asynchronous call to retrive (refresh) the users by query, and resolve KinveyReferences

Constructs an asynchronous request to retrieve User objects via a Query.

void sendEmailVerification(KinveyUserManagementCallback callback)
Asynchronous Call to initiate an Email Verification request

The email verification request initiates a server-side process to verify a user's email.

void update(User user, KinveyUserCallback callback)
Asynchronous Call to Save a given user

Constructs an asynchronous request to save a provided Kinvey user.

void update(KinveyUserCallback callback)
Asynchronous Call to Save the current user

Constructs an asynchronous request to save the current Kinvey user.

[Expand]
Inherited Methods
From class com.kinvey.java.User
From class com.google.api.client.json.GenericJson
From class com.google.api.client.util.GenericData
From class java.util.AbstractMap
From class java.lang.Object
From interface java.util.Map

Public Methods

public void create (String username, String password, KinveyUserCallback callback)

Asynchronous method to create a new Kinvey User.

Constructs an asynchronous request to create a Kinvey user with username and password, and returns the associated User object via a KinveyUserCallback. All metadata that is added to the user object prior to creating the user will be persisted to the Kinvey backend.

Sample Usage:

 kinveyClient.user().put("State","MA");
        kinveyClient.user().put("Age", 25);
        kinveyClient.user().create(mEditUserName.getText().toString(), mEditPassword.getText().toString(),
                new KinveyUserCallback() {

            public void onFailure(Throwable t) {
                CharSequence text = "Unable to create account.";
                Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
            

            public void onSuccess(User u) {
                CharSequence text = "Welcome " + u.getUserName() + ".";
                Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
            }
        });
    }
 

Parameters
username username of the Kinvey User
password password of the Kinvey user
callback KinveyUserCallback containing a new User instance.

public void delete (Boolean hardDelete, KinveyUserDeleteCallback callback)

Asynchronous Call to Delete the current user from the Kinvey backend

Constructs an asynchronous request to delete the current Kinvey user. The hardDelete flag determines whether the user is simply marked as inactive or completely erased from the Kinvey backend.

Sample Usage:

 User user = kinveyClient.user();
        user.delete(new KinveyUserDeleteCallback() {
            public void onFailure(Throwable e) { ... 
            public void onSuccess(Void v) { ... }
        });
    }
 

Parameters
hardDelete Erases user from Kinvey backend if true; inactivates the user if false.
callback KinveyUserDeleteCallback.

public void keepOfflineStorageOnLogout ()

Set a flag to allow local offline storage to persist after calls to logout.

Only use this method if each device will have a guaranteed consistent user and there are no concerns about security

public void login (KinveyUserCallback callback)

Asynchronous implicit user login.

Constructs an asynchronous request to log in an implicit (non-named) user and returns the associated User object via a KinveyUserCallback.

Sample Usage:

 kinveyClient.user().login(new KinveyUserCallback() {
               public void onFailure(Throwable t) { ... 
               public void onSuccess(User u) {
                   CharSequence text = "Welcome back!";
                   Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
               }
           });
       }
 

Parameters
callback KinveyUserCallback that returns a valid user object

public void login (String userid, String password, KinveyUserCallback callback)

Asynchronous Kinvey user login.

Constructs an asynchronous request to log in a Kinvey user with username and password, and returns the associated User object via a KinveyUserCallback.

Sample Usage:

 kinveyClient.user().login(mEditUserName.getText().toString(), mEditPassword.getText().toString(),
                   new KinveyUserCallback() {
               public void onFailure(Throwable t) {
                   CharSequence text = "Wrong username or password.";
                   Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
               
               public void onSuccess(User u) {
                   CharSequence text = "Welcome back," + u.getUserName() + ".";
                   Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
                   LoginActivity.this.startActivity(new Intent(LoginActivity.this,
                           SessionsActivity.class));
                   LoginActivity.this.finish();
               }
           });
       }
 

Parameters
userid userID of the Kinvey User
password password of the Kinvey user
callback KinveyUserCallback that returns a valid user object

public void loginAuthLink (String accessToken, String refreshToken, KinveyUserCallback callback)

public void loginFacebook (String accessToken, KinveyUserCallback callback)

Asynchronous Facebook login.

Constructs an asynchronous request to log in a Facebook user and returns the associated User object via a KinveyUserCallback. A valid Facebook access token must be obtained via the Facebook OAuth API and passed to this method.

Sample Usage:

            kinveyClient.user().loginFacebook(accessToken, new KinveyUserCallback() {

                public void onFailure(Throwable e) {
                    error(progressDialog, "Kinvey: " + e.getMessage());
                    Log.e(TAG, "failed Kinvey facebook login", e);
                }

                public void onSuccess(User u) {
                    Log.d(TAG, "successfully logged in with facebook");
                }
            });
 

Parameters
accessToken Facebook-generated access token.
callback KinveyUserCallback that returns a valid user object

public void loginGoogle (String accessToken, KinveyUserCallback callback)

Asynchronous Google login.

Constructs an asynchronous request to log in a Google user and returns the associated User object via a KinveyUserCallback. A valid Google access token must be obtained via the Google OAuth API and passed to this method.

Sample Usage:

       kinveyClient.user().loginGoogle(accessToken, new KinveyUserCallback() {

               public void onFailure(Throwable e) {
                   error(progressDialog, "Kinvey: " + e.getMessage());
                   Log.e(TAG, "failed Kinvey facebook login", e);
               

               public void onSuccess(User u) {
                   Log.d(TAG, "successfully logged in with facebook");
               }
           });
       }
 

Parameters
accessToken Google-generated access token.
callback KinveyUserCallback that contains a valid logged in user

public void loginKinveyAuthToken (String userId, String authToken, KinveyUserCallback callback)

Login to Kinvey services using a Kinvey user's _id and their valid Kinvey Auth Token. This method is provided to allow for cross-platform login, by reusing a session provided with another client library (or the REST api).

Parameters
userId the _id field of the user to login
authToken a valid Kinvey Auth token
callback KinveyUserCallback that contains a valid logged in user
Returns
  • a LoginRequest ready to be executed
Throws
IOException

public void loginLinkedIn (String accessToken, String accessSecret, String consumerKey, String consumerSecret, KinveyUserCallback callback)

Asynchronous Linked In login.

Constructs an asynchronous request to log in a Linked In user and returns the associated User object via a KinveyUserCallback. A valid Linked In access token, access secret, consumer key, and consumer secret must be obtained via the Linked In OAuth API and passed to this method.

Sample Usage:

 kinveyClient.user().loginLinkedIn(accessToken, accessSecret, LINKEDIN_CONSUMER_KEY, LINKEDIN_CONSUMER_SECRET,
                   new KinveyUserCallback() {

               public void onFailure(Throwable e) {
                   Log.e(TAG, "Failed Kinvey login", e)
               ;

               public void onSuccess(User r) {
                   Log.e(TAG, "Successfully logged in via Linked In");
               }
           });
      }

Parameters
accessToken Linked In-generated access token
accessSecret Linked In-generated access secret
consumerKey Linked In supplied developer consumer key
consumerSecret Linked In supplied developer consumer secret
callback KinveyUserCallback that returns a valid user object

public void loginSalesForce (String accessToken, String clientid, String refreshToken, String id, KinveyUserCallback callback)

Login to Kinvey Services using a Salesforce identity

Parameters
accessToken - provided by salesforce, after successful login
clientid - client id used by salesforce
refreshToken - provided by salesforce, after successful login
id - the salesforce id of the user
callback - KinveyUserCallback that contains a valid logged in user

public void loginTwitter (String accessToken, String accessSecret, String consumerKey, String consumerSecret, KinveyUserCallback callback)

Asynchronous Twitter login.

Constructs an asynchronous request to log in a Twitter user and returns the associated User object via a KinveyUserCallback. A valid Twitter access token, access secret, consumer key, and consumer secret must be obtained via the Twitter OAuth API and passed to this method.

Sample Usage:

 kinveyClient.user().loginTwitter(accessToken, accessSecret, TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET,
                   new KinveyUserCallback() {

               public void onFailure(Throwable e) {
                   Log.e(TAG, "Failed Kinvey login", e)
               ;

               public void onSuccess(User r) {
                   Log.e(TAG, "Successfully logged in via Twitter");
               }
           });
       }

Parameters
accessToken Twitter-generated access token
accessSecret Twitter-generated access secret
consumerKey Twitter supplied developer consumer key
consumerSecret Twitter supplied developer consumer secret
callback KinveyUserCallback that returns a valid user object

public User.LogoutRequest logout ()

Logs out the current user and clears the local sqllite3 storage

Returns
  • a Logout Request, ready to have *.execute() called

public void registerPush ()

This method is deprecated.
used for UrbanAirship, GCM only requires a call to myClient.push().initialize(...);

Register current user for push notifications

The registerPush method registers the current user for Push notifications. Push must have already been activated for the current application and a logged-in user context must exist. This must be called when enabling push for a user on a device. Once called, it does not have to be called again unless push has been explicitly disabled for a user, the app has been uninstalled / reinstalled, or app data has been cleared.

Sample Usage:

 kinveyClient.push().initialize(pushOptions,myApplication);
        kinveyClient.user().registerPush();
    
 

public void resetPassword (String username, KinveyUserManagementCallback callback)

Asynchronous Call to initiate a Password Reset request

The reset password request initiates a server-side process to reset a user's password. Once executed, a success callback is initiated. The user is then emailed by the server to receive the password reset. The user's email address must be stored in a property named 'email' in the User collection.

Sample Usage:

 kinveyClient.resetPassword(new KinveyClientCallback<User>() {
            public void onFailure(Throwable e) { ... 
            public void onSuccess() { ... }
        });
    }
 

Parameters
callback KinveyUserManagementCallback

public void retrieve (KinveyClientCallback<T> callback)

Asynchronous Call to Retrieve (refresh) the current user

Constructs an asynchronous request to refresh current user's data via the Kinvey back-end.

Sample Usage:

     User user = kinveyClient.user();
        user.retrieve(new KinveyUserCallback() {
            public void onFailure(Throwable e) { ... 
            public void onSuccess(User result) { ... }
        });
     }
 

Parameters
callback KinveyUserCallback containing a refreshed User instance.

public void retrieve (Query q, KinveyListCallback<T> callback)

Asynchronous Call to Retrieve users via a Query

Constructs an asynchronous request to retrieve User objects via a Query.

Sample Usage:

 User user = kinveyClient.user();
         user.retrieve(Query query, new KinveyUserListCallback() {
            public void onFailure(Throwable e) { ... 
            public void onSuccess(User[] result) { ... }
        });
    }
 

Parameters
callback KinveyUserListCallback for retrieved users.

public void retrieve (String[] resolves, KinveyUserCallback callback)

Asynchronous call to retrive (refresh) the current user, and resolve KinveyReferences

Constructs an asynchronous request to refresh current user's data via the Kinvey back-end.

Sample Usage:

     User user = kinveyClient.user();
        user.retrieve(new String[]{"myKinveyReferencedField", new KinveyUserCallback() {
           public void onFailure(Throwable e) { ... }
           public void onSuccess(User result) { ... }
        });
     }
 

Parameters
resolves an array of json keys maintaining KinveyReferences to be resolved
callback KinveyUserCallback containing refreshed user instance

public void retrieve (Query query, String[] resolves, KinveyUserListCallback callback)

Asynchronous call to retrive (refresh) the users by query, and resolve KinveyReferences

Constructs an asynchronous request to retrieve User objects via a Query.

Sample Usage:

 User user = kinveyClient.user();
          user.retrieve(Query query, new String[]{"myKinveyReferenceField", new KinveyUserListCallback() {
             public void onFailure(Throwable e) { ... }
             public void onSuccess(User[] result) { ... }
          });
       }
 

Parameters
query the query to execute defining users to return
resolves an array of json keys maintaining KinveyReferences to be resolved
callback KinveyUserListCallback containing an array of queried users

public void sendEmailVerification (KinveyUserManagementCallback callback)

Asynchronous Call to initiate an Email Verification request

The email verification request initiates a server-side process to verify a user's email. Once executed, a success callback is initiated. The user is then emailed by the server to receive the email verification. The user's email address must be stored in a property named 'email' in the User collection.

Sample Usage:

 kinveyClient.sendEmailVerification(new KinveyClientCallback<User>() {
            public void onFailure(Throwable e) { ... 
            public void onSuccess(Void result) { ... }
        });
 

Parameters
callback KinveyUserManagementCallback

public void update (User user, KinveyUserCallback callback)

Asynchronous Call to Save a given user

Constructs an asynchronous request to save a provided Kinvey user.

Ensure you have configured backend to allow for `Full` permissions on User edits through the console.

Sample Usage:

     kinveyClient.user().retrieve(new Query(), new KinveyUserListCallback(){
         public void onFailure(Throwable e) { ... 
         public void onSuccess(User[] result) {
             for (User u : result){
                 kinveyClient.User().update(u, new KinveyUserCallback() {
                     public void onFailure(Throwable e) { ... }
                     public void onSuccess(User result) { ... }
                 });
             }
         }
     });
     }
 

Parameters
callback KinveyUserCallback containing an updated User instance.

public void update (KinveyUserCallback callback)

Asynchronous Call to Save the current user

Constructs an asynchronous request to save the current Kinvey user.

Sample Usage:

     User user = kinveyClient.user();
        user.update(new KinveyUserCallback() {
            public void onFailure(Throwable e) { ... 
            public void onSuccess(User result) { ... }
        });
     }
 

Parameters
callback KinveyUserCallback containing an updated User instance.