-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(session): schedule session handling to background thread
SUITEDEV-26047 Co-authored-by: LasOri <[email protected]> Co-authored-by: kovacszsoltizsolt <[email protected]>
- Loading branch information
1 parent
e838907
commit b44611b
Showing
3 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
12 changes: 9 additions & 3 deletions
12
core/src/main/java/com/emarsys/core/app/AppLifecycleObserver.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
package com.emarsys.core.app | ||
|
||
import android.os.Handler | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleObserver | ||
import androidx.lifecycle.OnLifecycleEvent | ||
import com.emarsys.core.Mockable | ||
import com.emarsys.core.session.Session | ||
|
||
@Mockable | ||
class AppLifecycleObserver(private val session: Session) : LifecycleObserver { | ||
class AppLifecycleObserver(private val session: Session, | ||
private val coreSdkHandler: Handler) : LifecycleObserver { | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_START) | ||
fun onEnterForeground() { | ||
session.startSession() | ||
coreSdkHandler.post { | ||
session.startSession() | ||
} | ||
} | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | ||
fun onEnterBackground() { | ||
session.endSession() | ||
coreSdkHandler.post { | ||
session.endSession() | ||
} | ||
} | ||
} |
This file contains 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