Initializing the SDK

When users starts the application first call that you should perform on the Onegini SDK is OneginiClient#start method. The method is responsible for asynchronous initialization of the SDK. During this process the SDK can return errors, for example if the device is using deprecated android version or when the app version is outdated. Because of that the method expects a OneginiInitializationHandler in order to return initialization results.

Please note that no other SDK methods should be called before the start() method completes. Doing so has the potential to create race conditions that may lead to issues such as user or device deregistration.

When the SDK is successfully initialized the onSuccess method will be called. The Set that is passed in the method contains profiles that were detected on the device but removed on the Token Server side. In such case the SDK removes outdated profiles from and indicates which profiles were removed, so you can perform additional actions if needed (for example remove additional data from your app's memory).

If something wrong happens during initialization, the SDK will call onError method with OneginiInitializationError object containing error details. In some cases you might want to ignore some errors. For example some apps could ignore OneginiInitializationError.NETWORK_CONNECTIVITY_PROBLEM error type and allow user to perform some operations offline. On the other hand errors like OneginiInitializationError.OUTDATED_APP should be handled as soon as possible, because the SDK will return the same error in other calls (like authenticateUser) as long as they are not resolved. In case OneginiInitializationError.DEVICE_DEREGISTERED occur, you should clear local storage from device and all user's related data.

Code example OneginiClient initialization

  // method called during app's startup
  private void setupOneginiSDK() {
    final OneginiClient oneginiClient = OneginiSDK.getOneginiClient(this);
    oneginiClient.start(new OneginiInitializationHandler() {
      @Override
      public void onSuccess(final Set<UserProfile> removedUserProfiles) {
        // remove UserProfiles that were removed on the server side and proceed with you application flow
      }

      @Override
      public void onError(final OneginiInitializationError error) {
        handleInitializationErrors(error);
      }
    });
  }

  private void handleInitializationErrors(final OneginiInitializationError error) {
    @OneginiInitializationError.InitializationErrorType int errorType = error.getErrorType();
    switch (errorType) {
      case OneginiInitializationError.NETWORK_CONNECTIVITY_PROBLEM:
      case OneginiInitializationError.SERVER_NOT_REACHABLE:
        showToast("No internet connection.");
        break;
      case OneginiInitializationError.OUTDATED_APP:
        showToast("Please update this application in order to use it.");
        break;
      case OneginiInitializationError.OUTDATED_OS:
        showToast("Please update your Android version to use this application.");
        break;
      case OneginiInitializationError.DEVICE_DEREGISTERED:
        // in that case clear local storage from device and all user's related data
        onDeviceDeregistered();
        break;
      case OneginiInitializationError.DEVICE_REGISTRATION_ERROR:
      case OneginiInitializationError.GENERAL_ERROR:
      default:
        // Just display the error for other, less relevant errors
        displayError(error);
        break;
    }
  }