Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ android {
dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"

// androidx.startup runs our OneSignalInitializer during Application.onCreate so we can register
// an ActivityLifecycleCallbacks before MainActivity.onResume fires. This avoids the cold-start
// race where ReactApplicationContext.getCurrentActivity() returns null and the OneSignal SDK
// ends up holding an ApplicationContext instead of the real Activity.
implementation 'androidx.startup:startup-runtime:1.1.1'

// api is used instead of implementation so the parent :app project can access any of the OneSignal Java
// classes if needed. Such as com.onesignal.NotificationExtenderService
//
Expand Down
15 changes: 1 addition & 14 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application>
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data
android:name="com.onesignal.rnonesignalandroid.OneSignalInitializer"
android:value="androidx.startup" />
</provider>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,7 @@ public void initialize(String appId) {
}

ReactApplicationContext reactContext = getReactApplicationContext();
// Prefer the Activity captured by ActivityLifecycleTracker (registered via androidx.startup
// before MainActivity.onResume), then fall back to ReactApplicationContext's accessor and
// finally the ApplicationContext. Passing the real Activity lets the OneSignal SDK populate
// ApplicationService.current immediately, so requestPermission() can launch the OS dialog
// on the first cold-start instead of waiting for the next foreground event.
Context context = ActivityLifecycleTracker.getInstance().getCurrentActivity();
if (context == null) {
context = reactContext.getCurrentActivity();
}
Context context = reactContext.getCurrentActivity();
if (context == null) {
context = reactContext.getApplicationContext();
}
Expand Down
Loading