Skip to content

Move application lifecycle tracking in Android to the native wrapper#73

Merged
f2prateek merged 2 commits intosegmentio:masterfrom
FormidableLabs:bugfix/track-android-lifecycle-events
Jun 6, 2019
Merged

Move application lifecycle tracking in Android to the native wrapper#73
f2prateek merged 2 commits intosegmentio:masterfrom
FormidableLabs:bugfix/track-android-lifecycle-events

Conversation

@kadikraman
Copy link
Copy Markdown
Contributor

Fixes #36

Bug

Application lifecycle events (Application Installed, Opened, Updated) in Android are not being tracked.

Cause

In the analytics-android package, lifecycle events being tracked in the callback of onActivityCreated. However, neither onActivityCreated or onActivityStarted are ever called when using this library via the native wrapper. The other lifecycle methods, e.g. onActivityResumed, onActivityPaused, onActivityStopped etc are called as expected, which makes this a React Native specific bug.

The most likely reason for this is that MainActivity is created to run the React Native app before the native Analytics client is initialised, so that onActivityCreated and onActivityStarted for the MainActivity would have been triggered before the Analytics client has subscribed to them.

Solution

Move the lifecycle tracking code into the native wrapper.

The logic for lifecycle tracking is mirrored exactly as in analytics-android, and the trackAppLifecycleEvents flag will no longer be passed down to the native package, but handled in the wrapper.

Testing

Tested locally using Android Studio and a Nexus emulator, running Android 8.
Confirmed that each of the three lifecycle events are correctly sent and can be seen in the Live Debugger (https://app.segment.com/[name]/sources/android/debugger)

Screenshot 2019-06-06 at 11 37 27

@kadikraman kadikraman force-pushed the bugfix/track-android-lifecycle-events branch from 9baf5cb to 1c72d8a Compare June 6, 2019 14:04
@f2prateek
Copy link
Copy Markdown
Contributor

Merged #74. Let's rebase this, and the build should pick up the fixed config.

@kadikraman kadikraman force-pushed the bugfix/track-android-lifecycle-events branch from 1c72d8a to 686c316 Compare June 6, 2019 16:35
@f2prateek f2prateek merged commit 3e7b352 into segmentio:master Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android lifecycle events not captured

2 participants