Application-level Initialization
Custom Application Class
The Discover Android SDK must be initialized at the application level.
To achieve this, create a singleton class that extends the Android Application class. This class is responsible for managing the SDK lifecycle, including initialization, session handling, and cleanup.
Declare the custom Application class in
AndroidManifest.xml:
<application
android:name=".MyApplication"
... >
</application>
Discover SDK Initialization
Initialize the Discover SDK within the
onCreate() method of the
custom Application class to ensure it is available throughout the application
lifecycle.public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize Discover SDK
new Discover(this);
Discover.enable();
Discover.startSession();
// Log the current Discover session ID
Log.e("sessionID", Discover.getCurrentSessionId());
}
@Override
public void onLowMemory() {
// Notify SDK of low-memory conditions
Discover.onLowMemory();
super.onLowMemory();
}
@Override
public void onTerminate() {
// Disable SDK during application termination
Discover.disable();
super.onTerminate();
}
}
onCreate() |
Initializes the Discover SDK and starts a new session. |
onLowMemory() |
Allows the SDK to release internal resources under memory pressure. |
onTerminate() |
Gracefully disables the SDK during application shutdown. |
Note: Application-level initialization is mandatory for
features such as lifecycle tracking, session management, and automatic
instrumentation.