We can create an instance of the Service class by calling the constructor RService():

RService rService = new RService();

Even though the above code is a valid code, we advised against it. Instead, you should use the getServices method of the Rainbow class. Also, you should never create an instance of the RService class. This is a generic class, that has code that is used by the super-classes.

The Service class is used to keep track of the accounts (ServiceItem instance) that a user is already logged in. Thus, this class has two important properties: list and connectedList. They are both instances of the ArrayList<RServiceItem> class, and the list contains all accounts that a user has logged in, whereas the connectedList contains all active accounts.

An active account is a valid account. An account that a user can use it, and perform the available Actions on it. If an account is not active this means that the tokens are no longer valid, and thus, the user would have to re-login.

In addition to those two properties, a Service class has the following properties:

  • name[String]: This is the name of the Cloud Manager
  • connected[boolean}: A flag indicating if at least one account is a valid account
  • loginType[ServiceLoginType]: This is an enum which dictates the type of Login, and it has the following values:
    • sLogin: Normal Login
    • sOauth2: OAuth2 Login
    • sGoogle: This is Google Login (section OAuth2 Login, last paragraph)

The Services which use the OAuth2 Login have a few more properties:

  • oauthClientID[String]: You take this value from the Cloud Service’s site when you created your app
  • oauthClientSecret[String]: You take this value from the Cloud Service’s site when you created your app
  • redirectURI[String]: It has to be exactly the same with the one you entered at the Cloud Service’s site
  • scopes[String]: You need this only for OneDrive and Google Drive services

The properties for the OAuth2 Login are set when you call the method addServiceKeys: of the Rainbow class.

The MediaFireService class has the properties: appID and appKey. The SugarSyncService class has the properties: sugarSyncKey, sugarSyncPrivateKey, sugarSyncAppID. The method addServiceKeys: of the Rainbow class sets the value to these properties.

The Service class has some methods but you shouldn’t call them. They are used by the SDK. For example, the checkStatus() method is used to check if the accounts that a user is already logged in, are still valid. Most of them are, but for OAuth2 accounts, the access token may have expired. In that case, it will try to refresh it. Regardless of the result, it will post a message with the name UPDATE_UI_NEW_ACCOUNT with the LocalBroadcastManager.

Finally, the Service class is Parcelable and Serializable.