diff --git a/build.gradle b/build.gradle index 7645e9f8e..21560a2e9 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { ext { release = [ - versionName: "2.9.0", + versionName: "2.9.1", versionCode: 1 ] } diff --git a/sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt b/sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt index 1098d6fed..6e939362a 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt @@ -2,6 +2,8 @@ package com.qonversion.android.sdk import android.app.Activity import android.app.Application +import android.os.Handler +import android.os.Looper import androidx.lifecycle.ProcessLifecycleOwner import com.android.billingclient.api.BillingFlowParams import com.google.firebase.messaging.RemoteMessage @@ -18,10 +20,11 @@ object Qonversion : LifecycleDelegate { private var automationsManager: QAutomationsManager? = null private var logger = ConsoleLogger() private var isDebugMode = false + private val handler = Handler(Looper.getMainLooper()) init { val lifecycleHandler = AppLifecycleHandler(this) - ProcessLifecycleOwner.get().lifecycle.addObserver(lifecycleHandler) + postToMainThread { ProcessLifecycleOwner.get().lifecycle.addObserver(lifecycleHandler) } } override fun onAppBackground() { @@ -371,6 +374,15 @@ object Qonversion : LifecycleDelegate { internal fun logLaunchErrorForFunctionName(functionName: String?) { logger.release("$functionName function can not be executed. It looks like launch was not called.") } + + // Private functions + private fun postToMainThread(runnable: () -> Unit) { + if (Looper.myLooper() == Looper.getMainLooper()) { + runnable() + } else { + handler.post(runnable) + } + } } diff --git a/sdk/src/main/java/com/qonversion/android/sdk/di/module/AppModule.kt b/sdk/src/main/java/com/qonversion/android/sdk/di/module/AppModule.kt index 958244bed..eb9fdc913 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/di/module/AppModule.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/di/module/AppModule.kt @@ -68,6 +68,6 @@ class AppModule( } companion object { - private const val SDK_VERSION = "2.9.0" + private const val SDK_VERSION = "2.9.1" } } diff --git a/sdk/src/test/java/com/qonversion/android/sdk/services/QUserInfoServiceTest.kt b/sdk/src/test/java/com/qonversion/android/sdk/services/QUserInfoServiceTest.kt index a93c7d13c..5ecb07532 100644 --- a/sdk/src/test/java/com/qonversion/android/sdk/services/QUserInfoServiceTest.kt +++ b/sdk/src/test/java/com/qonversion/android/sdk/services/QUserInfoServiceTest.kt @@ -1,10 +1,9 @@ package com.qonversion.android.sdk.services -import com.qonversion.android.sdk.Constants import com.qonversion.android.sdk.storage.SharedPreferencesCache import com.qonversion.android.sdk.storage.TokenStorage import io.mockk.* -import junit.framework.Assert.assertEquals +import org.junit.Assert.assertEquals import org.assertj.core.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Nested