Getting the Current User

When a user logs in, the Kii Cloud SDK gets the user. While the user is logged in, you can get the user with an API.

When a user logs in, the SDK gets the user's access token from Kii Cloud. The SDK then stores the access token along with other user information in its static area for the details on the access token). In another word, the SDK remembers the "current user."

You can get the currently logged-in user by calling the getCurrentUser method.

  • // Get the currently logged-in user.
    KiiUser user = KiiUser.getCurrentUser();
    
    try {
      // Refresh the user to get the latest user info from Kii Cloud.
      user.refresh();
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • // Get the currently logged-in user.
    KiiUser user = KiiUser.getCurrentUser();
    
    // Refresh the user to get the latest user info from Kii Cloud.
    user.refresh(new KiiUserCallBack() {
      @Override
      public void onRefreshCompleted(int token, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
      }
    });

Call the refresh method to get the latest user information from Kii Cloud.

If the getCurrentUser method returns null, it means nobody is logged in.

The SDK can only handle one logged-in user at a time. If you want to handle multiple users, you need to login again as a different user. The login state of the previous user is lost by making this user switch.