Edit in GitHubLog an issue

Manual Lifecycle implementation

Import and register the Lifecycle extension

Java

Import the Lifecycle library:

Copied to your clipboard
import com.adobe.marketing.mobile.*;

Register the Lifecycle extension along with other extensions used with Mobile Core:

Copied to your clipboard
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
MobileCore.setApplication(this);
MobileCore.registerExtensions(Arrays.asList(
Lifecycle.EXTENSION,
...
), value -> {
// registration completion handler
});
}
}

Start collecting Lifecycle information

You can start collecting Lifecycle information at any time in your app, but we recommend that you start as soon as your app enters the foreground. This allows Lifecycle metrics to be correctly attributed to all of your users' activities for their current session.

Java

Do not start or stop Lifecycle in a Fragment.

In the onResume function of each of your Activities, start Lifecycle data collection:

Copied to your clipboard
@Override
public void onResume() {
MobileCore.setApplication(getApplication());
MobileCore.lifecycleStart(null);
}

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

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 setApplication in each of your Activities.

Pause Lifecycle collection

You should pause Lifecycle collection when the user stops using your app. The best time to do this is usually when your app has entered the background.

Java

Do not start or stop Lifecycle in a Fragment.

We recommend pausing Lifecycle from the onPause function in your Activities:

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.

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