Edit in GitHubLog an issue

Platform Services

The Platform Services are provided by the Adobe Experience Platform Mobile SDKs as part of the Mobile Core extension. These services provide shared functionality throughout the SDK that can be shared by extensions. For example, services provide shared functionality for networking, data queuing, and caching. For more information on services provided by the SDK please see the documentation in our iOS and Android repositories.

Accessing services

The MobileCore extension provides a shared ServiceProvider, responsible for maintaining the current set of provided services and any potential service overrides.

Some services provide wrapper classes. For example, the Log class is a wrapper around the LoggingService. However, in some cases, a wrapper class may not exist, and you may need to access a service directly from the ServiceProvider. The recommended way to do this is through a computed variable or directly through the ServiceProvider when required. This ensures that if the service is overridden, the service consumer always uses the correct service implementation.

For example, the following code snippet shows how to access CacheService.

Java

Copied to your clipboard
CacheService cacheService = ServiceProvider.getInstance().getCacheService();

Overriding services

The SDK allows overriding some services with your custom implemetation. This section walks through the steps necessary to create a custom Logging service, and register it with the SDK.

Java

First, implement a class that conforms to the Logging interface. Below is an example of a logging service that only prints out messages with a log level of Error.

Copied to your clipboard
class ErrorLogger implements Logging {
@Override
public void trace(String tag, String message) {}
@Override
public void debug(String tag, String message) {}
@Override
public void warning(String tag, String message) {}
@Override
public void error(String tag, String message) {
Log.e("ErrorLogger", message);
}
}

Next, use the setLoggingService API of ServiceProvider to update the logging service used by the SDK.

Copied to your clipboard
ServiceProvider.getInstance().setLoggingService(new ErrorLogger());

To revert to the default implementation of the LoggingService, you can set the logging service to nil using setLoggingService API.

Copied to your clipboard
ServiceProvider.getInstance().setLoggingService(null);
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.