@@ -28,6 +28,7 @@ import android.text.TextUtils
28
28
import com.clevertap.android.sdk.ActivityLifecycleCallback
29
29
import com.clevertap.android.sdk.CleverTapAPI
30
30
import com.clevertap.android.sdk.CleverTapInstanceConfig
31
+ import com.clevertap.android.sdk.CoreMetaData
31
32
import com.leanplum.LeanplumActivityHelper
32
33
import com.leanplum.callbacks.CleverTapInstanceCallback
33
34
import com.leanplum.internal.Constants
@@ -59,7 +60,7 @@ internal class CTWrapper(
59
60
private var identityManager = IdentityManager (deviceId, userId ? : deviceId, loggedInUserId)
60
61
private var firstTimeStart = identityManager.isFirstTimeStart()
61
62
62
- @SuppressLint(" WrongConstant" )
63
+ @SuppressLint(" WrongConstant" , " RestrictedApi " )
63
64
override fun launch (context : Context , callbacks : List <CleverTapInstanceCallback >) {
64
65
instanceCallbackList.addAll(callbacks)
65
66
@@ -89,13 +90,22 @@ internal class CTWrapper(
89
90
}
90
91
cleverTapInstance?.apply {
91
92
setLibrary(" Leanplum" )
92
- if (! ActivityLifecycleCallback .registered && LeanplumActivityHelper .getCurrentActivity() != null ) {
93
- ActivityLifecycleCallback .register(context.applicationContext as ? Application )
94
- if (! LeanplumActivityHelper .isActivityPaused() && ! CleverTapAPI .isAppForeground()) {
95
- // Trigger onActivityResumed because onResume of ActivityLifecycle has already been executed
96
- // in this case. This could happen on first start with ct migration. This method will also
97
- // trigger App Launched if it was not send already.
98
- CleverTapAPI .onActivityResumed(LeanplumActivityHelper .getCurrentActivity())
93
+ if (LeanplumActivityHelper .getCurrentActivity() != null ) {
94
+ if (! ActivityLifecycleCallback .registered) {
95
+ ActivityLifecycleCallback .register(context.applicationContext as ? Application )
96
+ if (! LeanplumActivityHelper .isActivityPaused() && ! CleverTapAPI .isAppForeground()) {
97
+ // Trigger onActivityResumed because onResume of ActivityLifecycle has already been executed
98
+ // in this case. This could happen on first start with ct migration. This method will also
99
+ // trigger App Launched if it was not send already.
100
+ CleverTapAPI .onActivityResumed(LeanplumActivityHelper .getCurrentActivity(), cleverTapID)
101
+ }
102
+ } else if (CoreMetaData .getCurrentActivity() == null && ! LeanplumActivityHelper .isActivityPaused()) {
103
+ // If CT ActivityLifecycleCallback was registered before LP had created the CT instance
104
+ // CleverTapAPI.onActivityResumed would have not executed its initialization logic
105
+ // (CleverTapAPI.instances would still have been null). This is checked here by
106
+ // CoreMetaData.getCurrentActivity() == null.
107
+ // In this case call onActivityResumed explicitly.
108
+ CleverTapAPI .onActivityResumed(LeanplumActivityHelper .getCurrentActivity(), cleverTapID)
99
109
}
100
110
}
101
111
if (identityManager.isAnonymous()) {
0 commit comments