Skip to content

Commit

Permalink
Set lifecycle tracking off by default (close #443)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBenny committed Apr 26, 2021
1 parent 063ea55 commit 706bfef
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions snowplow-demo-app/build.gradle
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

project.ext {
archLifecycleVersion = "1.1.1"
archLifecycleVersion = "2.2.0"
}

android {
Expand Down Expand Up @@ -43,7 +43,7 @@ android {
}

dependencies {
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-extensions:$project.archLifecycleVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':snowplow-android-tracker')
implementation 'androidx.browser:browser:1.3.0'
Expand Down
7 changes: 4 additions & 3 deletions snowplow-tracker/build.gradle
Expand Up @@ -11,7 +11,7 @@ jacoco {
}

project.ext {
archLifecycleVersion = "1.1.1"
archLifecycleVersion = "2.2.0"
}

android {
Expand Down Expand Up @@ -76,11 +76,12 @@ android {
}

dependencies {
implementation 'androidx.annotation:annotation:1.1.0'
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation 'androidx.annotation:annotation:1.2.0'
compileOnly "androidx.lifecycle:lifecycle-extensions:$project.archLifecycleVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
// test
testImplementation "androidx.lifecycle:lifecycle-extensions:$project.archLifecycleVersion"
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
@@ -1,7 +1,6 @@
package com.snowplowanalytics.snowplow.internal.utils;

import androidx.annotation.NonNull;
import androidx.lifecycle.Observer;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Assert;
Expand Down
Expand Up @@ -257,7 +257,7 @@ public void setDiagnosticAutotracking(boolean diagnosticAutotracking) {
* geoLocationContext = false;
* screenContext = true;
* screenViewAutotracking = true;
* lifecycleAutotracking = true;
* lifecycleAutotracking = false;
* installAutotracking = true;
* exceptionAutotracking = true;
* diagnosticAutotracking = false;
Expand All @@ -278,7 +278,7 @@ public TrackerConfiguration(@NonNull String appId) {
geoLocationContext = false;
screenContext = true;
screenViewAutotracking = true;
lifecycleAutotracking = true;
lifecycleAutotracking = false;
installAutotracking = true;
exceptionAutotracking = true;
diagnosticAutotracking = false;
Expand Down
Expand Up @@ -17,11 +17,10 @@
import android.content.Context;

import androidx.annotation.Nullable;
import androidx.annotation.NonNull;
import androidx.lifecycle.ProcessLifecycleOwner;
import android.os.Handler;

import androidx.annotation.NonNull;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -563,15 +562,17 @@ private Tracker(@NonNull TrackerBuilder builder) {
trackerSession = Session.getInstance(context, foregroundTimeout, backgroundTimeout, timeUnit, namespace, callbacks);
}

// If lifecycleEvents is True
if (this.lifecycleEvents || this.sessionContext) {

if (this.lifecycleEvents) {
// addObserver must execute on the mainThread
Handler mainHandler = new Handler(context.getMainLooper());
mainHandler.post(new Runnable() {
@Override
public void run() {
ProcessLifecycleOwner.get().getLifecycle().addObserver(new ProcessObserver());
try {
ProcessLifecycleOwner.get().getLifecycle().addObserver(new ProcessObserver());
} catch (NoClassDefFoundError e) {
Logger.e(TAG,"Class 'ProcessLifecycleOwner' not found. The tracker can't track lifecycle events.");
}
}
});
}
Expand Down
@@ -1,7 +1,6 @@
package com.snowplowanalytics.snowplow.internal.utils;

import androidx.annotation.NonNull;
import androidx.lifecycle.Observer;

import java.lang.ref.WeakReference;
import java.util.HashMap;
Expand Down

0 comments on commit 706bfef

Please sign in to comment.