@@ -28,6 +28,7 @@ import android.text.TextUtils
2828import com.clevertap.android.sdk.ActivityLifecycleCallback
2929import com.clevertap.android.sdk.CleverTapAPI
3030import com.clevertap.android.sdk.CleverTapInstanceConfig
31+ import com.clevertap.android.sdk.CoreMetaData
3132import com.leanplum.LeanplumActivityHelper
3233import com.leanplum.callbacks.CleverTapInstanceCallback
3334import com.leanplum.internal.Constants
@@ -59,7 +60,7 @@ internal class CTWrapper(
5960 private var identityManager = IdentityManager (deviceId, userId ? : deviceId, loggedInUserId)
6061 private var firstTimeStart = identityManager.isFirstTimeStart()
6162
62- @SuppressLint(" WrongConstant" )
63+ @SuppressLint(" WrongConstant" , " RestrictedApi " )
6364 override fun launch (context : Context , callbacks : List <CleverTapInstanceCallback >) {
6465 instanceCallbackList.addAll(callbacks)
6566
@@ -89,13 +90,22 @@ internal class CTWrapper(
8990 }
9091 cleverTapInstance?.apply {
9192 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)
99109 }
100110 }
101111 if (identityManager.isAnonymous()) {
0 commit comments