Foundation

The Foundation component includes modules that can be used to integrate your application with SAP Cloud Platform Mobile Services, including communication, authentication, caching, remote notifications, and more.

Note

This section assumes a familiarity with SAP Cloud Platform concepts, basic administration, and application configuration. See the SAP Cloud Platform Mobile Services documentation for more information on these services.

Initializing SDK

Since there are many modules in the Foundation component, using them in the client code to integrate your application with SAP Cloud Platform Mobile Services will require lots of boilerplate code in the mobile application. To reduce the boilerplate code from your mobile application, a new API is introduced as below:

1
2
3
4
5
6
7
public static void start(
        @NonNull Application application, 
        @NonNull OkHttpClient httpClient,
        @NonNull SettingsParameters settingsParameter,
        @Nullable Class<? extends MobileService>... services) {
    ...
}

When both 'settingsParameter' and 'httpClient' are ready, this method can be called to initialize all the 'services', that is, the modules you want to use in your application, for example, 'Push', 'Usage', etc.

Note

Since the initialization process will depend on the lifycycle of the mobile application, before invoking the 'start' method, make sure the follow lifecycle callback is registered.

1
registerActivityLifecycleCallbacks(AppLifecycleCallbackHandler.getInstance());

The parameters are explained below:

  1. SettingsParameter

    SettingsParameter mainly contains the following attributes which will be needed in various API calls:

    • BackendURL - The server URL from the mobile services application APIs end points. This is used as the base URL for constructing various REST API end points.
    • ApplicationId - The application Id from the application definition in mobile services
    • DeviceId - The device Id is used to identify the device in the mobile application that is running. It is best to use an Id that is same across application sessions. It is recommended to use ANDROID_ID for this. The Device Id plays a role in push notifications and valuable Admin functionality in mobile services.
      1
      2
      3
      import android.provider.Settings.Secure;
      ...
      String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
      
    • ApplicationVersion - The application version for your mobile application. This version is used in reporting APIs.
  2. OkHttpClient

    This will be used for API calls in your application, and it will be different based on the authentication method you're using.

    Note

    Please use 'ClientProvider.get()' to get http client instance after invoking 'MobileServices.start' since the initializer will add additional interceptor into it.

  3. Class<? extends MobileService>... services

    This parameter represents all the services to be initialized in your application. Currently the following services are supported:

    This parameter only takes the class name as the value, it means most of the services have default values defined inside, for example, the default 'UsageService' will use 'auto session' feature and a default usage store name, if you want to define your own settings, you can do that before calling the 'start' method.

    Please follow the links above to see the details.