Edit in GitHubLog an issue

Lifecycle

Sessions contain information about the app's current lifecycle, such as the device information, the application install or upgrade information, the session start and pause times, the number of application launches, and additional context data that is provided by the developer through the LifecycleStart API. Session data is persisted, so it is available across application launches.

Add Lifecycle to your app

  1. Add the Lifecycle extension and its dependency, the Mobile Core extension to your project using the app's Gradle file.

Kotlin

Copied to your clipboard
implementation(platform("com.adobe.marketing.mobile:sdk-bom:3.+"))
implementation("com.adobe.marketing.mobile:core")
implementation("com.adobe.marketing.mobile:lifecycle")

Groovy

Copied to your clipboard
implementation platform('com.adobe.marketing.mobile:sdk-bom:3.+')
implementation 'com.adobe.marketing.mobile:core'
implementation 'com.adobe.marketing.mobile:lifecycle'
  1. Import the Lifecycle and MobileCore extensions in your application's main activity.
Copied to your clipboard
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Lifecycle;

Register Lifecycle with Mobile Core and add appropriate Start/Pause calls

Java

  1. Register the Lifecycle extension:
Copied to your clipboard
public class MobileApp extends Application {
@Override
public void onCreate() {
super.onCreate();
MobileCore.setApplication(this);
List<Class<? extends Extension>> extensions = Arrays.asList(Lifecycle.EXTENSION, ...);
MobileCore.registerExtensions(extensions, o -> {
// Any other post registration processing
});
}
}
  1. In the onResume function, start the lifecycle data collection:
Copied to your clipboard
@Override
public void onResume() {
MobileCore.setApplication(getApplication());
MobileCore.lifecycleStart(null);
}

Setting the application is only necessary on activities that are entry points for your application. However, setting the application on each Activity has no negative impact and ensures that the SDK always has the necessary reference to your application. We recommend that you call setApplicationin each of your activities.

  1. In the onPause function, pause the lifecycle data collection:
Copied to your clipboard
@Override
public void onPause() {
MobileCore.lifecyclePause();
}

To ensure accurate session and crash reporting, this call must be added to every activity.

  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.