Skip to content

Get Current User

Description

Android or Java applications can retrieve a BackendlessUser object representing the currently logged in user using the operation presented below.

Method

Blocking API:

public BackendlessUser Backendless.UserService.CurrentUser( boolean reload );

Non-blocking API:

public void Backendless.UserService.CurrentUser( boolean reload, final AsyncCallback<BackendlessUser> responder );

where:

Argument                Description
reload Optional parameter. Defaults to false. When this parameter is set totrue, the operation is forced to retrieve the user data from the Backendless servers. Otherwise, your application returns cached user data stored locally. Boolean value.

Return Value

BackendlessUser object containing user data. The object has the values for all the properties stored in the Users data table.

If a user is not logged in, the operation returns null.

Example

The example below retrieves the current BackendlessUser object containing user data.

Blocking API:

BackendlessUser user = Backendless.UserService.CurrentUser( true );

Non-blocking API:

Backendless.UserService.CurrentUser( true, new AsyncCallback<BackendlessUser>()
  {
    @Override
    public void handleResponse( BackendlessUser response )
    {
      // some additional logic for reloaded user
    }
    @Override
    public void handleFault( BackendlessFault fault )
    {
      // error handling logic
    }
  } );

Codeless Reference

user_service_codeless_get_current_user

where:

Argument                Description
reload Optional parameter. When this option is selected, the operation is forced to retrieve the user data from the Backendless servers. Otherwise, your application returns cached user data stored locally.

Returns the BackendlessUser object containing user data. The object has the values for all the properties stored in the Users data table. If a user is not logged in, the method returns null.

Consider the following record in the Users data table:

user_service_codeless_example_get_current_user_2

For demonstration purposes, the example below showcases the operation's output for two scenarios when:

  1. A user is not logged in; When the "alice@wonderland.com" user is not logged in, the operation returns null.
  2. A user is logged in; When the "alice@wonderland.com" user is logged in, the operation returns the BackendlessUser object:

user_service_codeless_example_get_current_user

The output will look as shown below after the Codeless logic runs:

user_service_codeless_example_get_current_user_3