Move application lifecycle tracking in Android to the native wrapper#73
Merged
f2prateek merged 2 commits intosegmentio:masterfrom Jun 6, 2019
Conversation
9baf5cb to
1c72d8a
Compare
f2prateek
approved these changes
Jun 6, 2019
Contributor
|
Merged #74. Let's rebase this, and the build should pick up the fixed config. |
1c72d8a to
686c316
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, neitheronActivityCreatedoronActivityStartedare ever called when using this library via the native wrapper. The other lifecycle methods, e.g.onActivityResumed,onActivityPaused,onActivityStoppedetc are called as expected, which makes this a React Native specific bug.The most likely reason for this is that
MainActivityis created to run the React Native app before the native Analytics client is initialised, so thatonActivityCreatedandonActivityStartedfor theMainActivitywould 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 thetrackAppLifecycleEventsflag 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)