Skip to content

Commit

Permalink
Ensure app_init message is generated in background
Browse files Browse the repository at this point in the history
  • Loading branch information
willpassidomo authored and Sam Dozor committed May 24, 2017
1 parent f272ce8 commit 93f6f50
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,10 @@ public void onActivityResumed(Activity activity) {
}

mCurrentSession.updateBackgroundTime(mLastStoppedTime, getTime());
mLastForegroundTime = getTime();

if (!mInitialized) {
mInitialized = true;
logStateTransition(Constants.StateTransitionType.STATE_TRANS_INIT,
mCurrentActivityName,
0,
0,
previousSessionUri,
previousSessionParameters,
previousSessionPackage,
0);
mLastForegroundTime = getTime();
initialize(mCurrentActivityName, previousSessionUri, previousSessionParameters, previousSessionPackage);
} else if (isBackgrounded() && mLastStoppedTime.get() > 0) {
logStateTransition(Constants.StateTransitionType.STATE_TRANS_FORE,
mCurrentActivityName,
Expand All @@ -177,7 +169,6 @@ public void onActivityResumed(Activity activity) {
previousSessionPackage,
interruptions);
Logger.debug("App foregrounded.");
mLastForegroundTime = getTime();
}

if (mCurrentActivityReference != null) {
Expand Down Expand Up @@ -233,6 +224,9 @@ public void run() {
}

public void ensureActiveSession() {
if (!mInitialized) {
initialize(null, null, null, null);
}
Session session = getSession();
session.mLastEventTime = System.currentTimeMillis();
if (!session.isActive()) {
Expand Down Expand Up @@ -300,6 +294,18 @@ public void run() {
}, mConfigManager.getSessionTimeout());
}

private void initialize(String currentActivityName, String previousSessionUri, String previousSessionParameters, String previousSessionPackage) {
mInitialized = true;
logStateTransition(Constants.StateTransitionType.STATE_TRANS_INIT,
currentActivityName,
0,
0,
previousSessionUri,
previousSessionParameters,
previousSessionPackage,
0);
}

public void onActivityCreated(Activity activity, Bundle savedInstanceState){
MParticle.getInstance().getKitManager().onActivityCreated(activity, savedInstanceState);
}
Expand Down

0 comments on commit 93f6f50

Please sign in to comment.