# Interceptor Lifecycle

It is of most importance to properly manage Codavel SDK interceptor lifecycle.

Internally, when Codavel SDK interceptor is started, it launches a service that manages all its components, and during its startup process, it takes some milliseconds to launch. Thus, you should carefully choose the moment to launch it properly. Failing to do it correctly may cause a bad user-experience.

# Start Interceptor

The Codavel SDK interceptor should be started on a background thread and during a moment when no network request have yet been requested.

As such, we recommend to start the interceptor in the following momments:

  • In a Splash screen Activity
  • In the app's Application class
  • In a background service (if your app already makes use of such mechanism to manage its network requests)
  • In a specific Activity responsible for a specific content

When launching from an Activity or Application class, you should do via an ExecutorService (opens new window).

# Sample

This is the recommended way to start the Codavel SDK interceptor, using an ExecutorService.

  • Java
  • Kotlin
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(new Runnable() {
    @Override
    public void run() {
        InterceptorSingleton.startInterceptor(getApplication(), config);
    }
});
1
2
3
4
5
6
7

# Stop Interceptor

If you start the interceptor as soon as possible in your app, such as in a Splash screen Activity, there is no need to force the interceptor to stop. The interceptor will follow the app lifecycle and will be destroyed when the app is destroyed.

However, suppose you have a specific place or Activity where you expect to use Codavel CDN. In that case, we recommend you stop the Codavel SDK interceptor when the user leaves that place or Activity.

# Diagnostic Tool

The Diagnostic Tool is a feature that, when enabled, validates and assesses if the main Codavel SDK is properly integrated with your app.

# Enable the Diagnostic Tool

Assuming you've integrated bolina into your app with one of the available libs, add the following block of code after the start of the interceptor.

  • Java
  • Kotlin

DiagnosticTool.runDiagnosticTool(okHttpClient, getApplication().getApplicationContext());

1
2
3

Note that the okHttpClient must be the same used on the Codavel SDK integration.

# Diagnostic Tool results

In your Codavel private area, you will have access to a dashboard where you can visualize all the information collected by this tool and identify any issue with your integration.