Skip to content

Commit eaabbe2

Browse files
committed
Fix outside package target activities not opening
This fix includes any launch URLs set to open the browser or another app The issue was due to an Activity backstack not being built correctly. Both `NotificationOpenedReceiver` and the target `Activity` were launched with `FLAG_ACTIVITY_NEW_TASK` however this means when `NotificationOpenedReceiver` is finished it does not bring up the target since it is on a different task. The Android flag `allowTaskReparenting` allows this to happen, however this can effect the backstack of the main task which we don't want to do. Setting `android:taskAffinity` does `FLAG_ACTIVITY_NEW_TASK` and `allowTaskReparenting` for us. By setting the value to "" (empty string) it prevents any side effects on existing tasks as it means it has no affinity to associate it with. This allowed us to clean up some runtime logic to add `FLAG_ACTIVITY_NEW_TASK` and others we no longer need now.
1 parent 70b6297 commit eaabbe2

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

OneSignalSDK/onesignal/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
android:name="com.onesignal.NotificationOpenedReceiver"
137137
android:noHistory="true"
138138
android:excludeFromRecents="true"
139+
android:taskAffinity=""
139140
android:theme="@android:style/Theme.Translucent.NoTitleBar"
140141
android:exported="true" />
141142

OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,9 @@ class GenerateNotificationOpenIntent(
1717
): Intent {
1818
// We use SINGLE_TOP and CLEAR_TOP as we don't want more than one OneSignal invisible click
1919
// tracking Activity instance around.
20-
var intentFlags =
20+
val intentFlags =
2121
Intent.FLAG_ACTIVITY_SINGLE_TOP or
2222
Intent.FLAG_ACTIVITY_CLEAR_TOP
23-
if (!startApp) {
24-
// If we don't want the app to launch we put OneSignal's invisible click tracking Activity on it's own task
25-
// so it doesn't resume an existing one once it closes.
26-
intentFlags =
27-
intentFlags or (
28-
Intent.FLAG_ACTIVITY_NEW_TASK or
29-
Intent.FLAG_ACTIVITY_MULTIPLE_TASK or
30-
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
31-
)
32-
}
3323

3424
return Intent(
3525
context,

0 commit comments

Comments
 (0)