Skip to content

Commit 07f154e

Browse files
chore: [SDK-4743] remove Cordova lifecycle nudge
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4e74647 commit 07f154e

1 file changed

Lines changed: 0 additions & 46 deletions

File tree

src/android/com/onesignal/cordova/OneSignalPush.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@
2626
*/
2727
package com.onesignal.cordova;
2828

29-
import android.app.Activity;
30-
import android.app.Application;
3129
import com.onesignal.OneSignal;
3230
import com.onesignal.common.OneSignalWrapper;
33-
import com.onesignal.core.internal.application.IApplicationService;
3431
import com.onesignal.debug.internal.logging.Logging;
3532
import com.onesignal.inAppMessages.IInAppMessage;
3633
import com.onesignal.inAppMessages.IInAppMessageClickEvent;
@@ -378,13 +375,6 @@ public boolean init(CallbackContext callbackContext, JSONArray data) {
378375
String appId = data.getString(0);
379376
OneSignal.initWithContext(this.cordova.getActivity(), appId);
380377

381-
// If the SDK was initialized from a non-Activity context (FCM/work
382-
// managers, SyncJobService) before this call, initWithContext above
383-
// short-circuits and ApplicationService.start never re-runs, so its
384-
// ALC missed MainActivity.onResume and isInForeground stays false.
385-
// Forward the missed events now.
386-
nudgeApplicationServiceForeground();
387-
388378
// add listeners
389379
OneSignal.getInAppMessages().addLifecycleListener(this);
390380
OneSignal.getInAppMessages().addClickListener(this);
@@ -398,42 +388,6 @@ public boolean init(CallbackContext callbackContext, JSONArray data) {
398388
}
399389
}
400390

401-
/**
402-
* Forward the missed activity-resume to the SDK so isInForeground is
403-
* correct on cold start. No-op if the SDK already saw the resume.
404-
*
405-
* TODO: Replace with a public native-SDK entry point (e.g.
406-
* OneSignal.onActivityForegrounded(Activity)) once the Android SDK
407-
* exposes one, instead of casting IApplicationService to
408-
* ActivityLifecycleCallbacks here.
409-
*/
410-
private void nudgeApplicationServiceForeground() {
411-
final Activity activity = this.cordova.getActivity();
412-
if (activity == null) return;
413-
414-
// cordova.execute() runs on the WebView thread, but Android's
415-
// ActivityLifecycleCallbacks are normally invoked on the main thread.
416-
// Hop to the UI thread so we don't race real framework callbacks.
417-
activity.runOnUiThread(() -> {
418-
final Activity currentActivity = this.cordova.getActivity();
419-
if (currentActivity == null) return;
420-
421-
IApplicationService appSvc;
422-
try {
423-
appSvc = OneSignal.INSTANCE.getServices().getServiceOrNull(IApplicationService.class);
424-
} catch (Throwable t) {
425-
return;
426-
}
427-
if (appSvc == null) return;
428-
if (appSvc.isInForeground() && appSvc.getCurrent() == currentActivity) return;
429-
if (!(appSvc instanceof Application.ActivityLifecycleCallbacks)) return;
430-
431-
Application.ActivityLifecycleCallbacks callbacks = (Application.ActivityLifecycleCallbacks) appSvc;
432-
callbacks.onActivityStarted(currentActivity);
433-
callbacks.onActivityResumed(currentActivity);
434-
});
435-
}
436-
437391
@Override
438392
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
439393
boolean result = false;

0 commit comments

Comments
 (0)