Lifecycle API reference

Version of the Lifecycle extension

The extensionVersion() API returns the version of the Lifecycle extension that is registered with the Mobile Core extension.
To get the version of the Lifecycle extension, use the following code sample:
Android
iOS (AEP 3.x)
iOS (ACP 2.x)
React Native
Flutter
Cordova
Unity
Xamarin

Java

1
String lifecycleExtensionVersion = Lifecycle.extensionVersion();
Copied!
Swift
1
let version = Lifecycle.extensionVersion
Copied!
Objective C
1
NSString *version = [AEPMobileLifecycle extensionVersion];
Copied!
Objective C
1
NSString *lifecycleExtensionVersion = [ACPLifecycle extensionVersion];
Copied!
Swift
1
let lifecycleExtensionVersion = ACPLifecycle.extensionVersion()
Copied!

JavaScript

1
ACPLifecycle.extensionVersion().then(lifecycleExtensionVersion => console.log("AdobeExperienceSDK: ACPLifecycle version: " + lifecycleExtensionVersion));
Copied!

Dart

1
String lifeycycleExtensionVersion = await FlutterACPLifecycle.extensionVersion;
Copied!

Cordova

1
ACPLifecycle.extensionVersion(function(version) {
2
console.log("ACPLifecycle version: " + version);
3
}, function(error) {
4
console.log(error);
5
});
Copied!

C#

1
string lifecycleVersion = ACPLifecycle.ExtensionVersion();
Copied!

C#

1
string lifecycleVersion = ACPLifecycle.ExtensionVersion();
Copied!

Lifecycle Start

Starts the collection of lifecycle data.
For Analytics use case: Use this API to start a new lifecycle session or resume a previously paused lifecycle session. If a previously paused session timed out, then a new session is created. If a current session is running, then calling this method does nothing.
For Platform use case: Use this API to dispatch a Lifecycle Application Foreground event when the application is launched.

lifecycleStart

Android
iOS (AEP 3.x)
iOS (ACP 2.x)
React Native
Cordova
Unity
Xamarin

Java

Syntax
1
public static void lifecycleStart(final Map<String, String> additionalContextData);
Copied!
Example
1
MobileCore.lifecycleStart(null);
Copied!
If you need to collect additional lifecycle data:
1
contextData.put("myapp.category", "Game");
2
MobileCore.lifecycleStart(additionalContextData);
Copied!
This method should be called from the Activity onResume method.

Swift

1
MobileCore.lifecycleStart(additionalContextData: ["contextDataKey": "contextDataVal"])
Copied!

Objective-C

Syntax
1
@objc(lifecycleStart:)
2
static func lifecycleStart(additionalContextData: [String: Any]?)
Copied!
Example
1
[AEPMobileCore lifecycleStart:nil];
Copied!
If you need to collect additional lifecycle data:
1
[AEPMobileCore lifecycleStart:@{@"contextDataKey": @"contextDataVal"}];
Copied!

Objective-C

Syntax
1
+ (void) lifecycleStart: (nullable NSDictionary<NSString*, NSString*>*) additionalContextData;
Copied!
Example
1
[ACPCore lifecycleStart:nil];
Copied!
If you need to collect additional lifecycle data:
1
[ACPCore lifecycleStart:@{@"state": @"appResume"}];
Copied!

Swift

1
ACPCore.lifecycleStart(["state": "appResume"])
Copied!

JavaScript

Note: Implementing Lifecycle via JavaScript may lead to inaccurate Lifecycle metrics, therefore we recommend implementing Lifecycle in native Android and iOS code. However, these APIs are still provided in JavaScript to support flexible Lifecycle implementations.
Syntax
1
lifecycleStart(additionalContextData?: { string: string });
Copied!
Example
1
ACPCore.lifecycleStart({"lifecycleStart": "myData"});
Copied!

Cordova

When using Cordova, the lifecycleStart method call must be made in native code which is shown under the Android and iOS tabs.

C#

When using Unity, the LifecycleStart method call must be made from the OnApplicationPause method.
1
private void OnApplicationPause(bool pauseStatus)
2
{
3
if (!pauseStatus)
4
{
5
ACPCore.LifecyclePause();
6
}
7
else
8
{
9
var cdata = new Dictionary<string, string>();
10
cdata.Add("launch.data", "added");
11
ACPCore.LifecycleStart(cdata);
12
}
13
}
Copied!

C#

iOS
When using iOS, the LifecycleStart method call must be made from the OnActivated method.
1
public override void OnActivated(UIApplication uiApplication)
2
{
3
base.OnActivated(uiApplication);
4
ACPCore.LifecycleStart(null);
5
}
Copied!
Android
When using Android, the LifecycleStart method call must be made from the OnResume method.
1
protected override void OnResume()
2
{
3
base.OnResume();
4
ACPCore.LifecycleStart(null);
5
}
Copied!

Lifecycle Pause

Pauses the collection of lifecycle data.
For Analytics use case: Use this API to pause the collection of lifecycle data.
For Platform use case: Use this API to dispatch a Lifecycle Application Background event when the application closes.

lifecyclePause

Android
iOS (AEP 3.x)
iOS (ACP 2.x)
React Native
Cordova
Unity
Xamarin

Java

Syntax
1
public static void lifecyclePause()
Copied!
Example
1
MobileCore.lifecyclePause();
Copied!

Swift

1
MobileCore.lifecyclePause()
Copied!

Objective-C

Syntax
1
@objc(lifecyclePause)
2
static func lifecyclePause()
Copied!
Example
1
[AEPMobileCore lifecyclePause];
Copied!

Objective-C

Syntax
1
+ (void) lifecyclePause;
Copied!
Example
1
[ACPCore lifecyclePause];
Copied!

Swift

1
ACPCore.lifecyclePause()
Copied!

JavaScript

Note: Implementing Lifecycle via JavaScript may lead to inaccurate Lifecycle metrics, therefore we recommend implementing Lifecycle in native Android and iOS code. However, these APIs are still provided in JavaScript to support flexible Lifecycle implementations.
Syntax
1
lifecyclePause();
Copied!
Example
1
ACPCore.lifecyclePause();
Copied!

Cordova

When using Cordova, the lifecyclePause method call must be made in native code which is shown under the Android and iOS tabs.

C#

When using Unity, the LifecyclePause method call must be made from the OnApplicationPause method.
1
private void OnApplicationPause(bool pauseStatus)
2
{
3
if (!pauseStatus)
4
{
5
ACPCore.LifecyclePause();
6
}
7
else
8
{
9
var cdata = new Dictionary<string, string>();
10
cdata.Add("launch.data", "added");
11
ACPCore.LifecycleStart(cdata);
12
}
13
}
Copied!

C#

iOS
When using iOS, the LifecyclePause method call must be made from the OnResignActivation method.
1
public override void OnResignActivation(UIApplication uiApplication)
2
{
3
base.OnResignActivation(uiApplication);
4
ACPCore.LifecyclePause();
5
}
Copied!
Android
When using Android, the LifecyclePause method call must be made from the OnPause method.
1
protected override void OnPause()
2
{
3
base.OnPause();
4
ACPCore.LifecyclePause();
5
}
Copied!
Last modified 28d ago