Skip to content

Commit 00e1792

Browse files
authored
Merge pull request #2129 from OneSignal/fix/xiaomi_foreground_on_click
[Fix] Xiaomi notification click not foregrounding app
2 parents f5bf424 + 8f66f8e commit 00e1792

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/activities/NotificationOpenedActivityBase.kt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,26 @@ import com.onesignal.notifications.internal.open.INotificationOpenedProcessor
3636
abstract class NotificationOpenedActivityBase : Activity() {
3737
override fun onCreate(savedInstanceState: Bundle?) {
3838
super.onCreate(savedInstanceState)
39-
if (!OneSignal.initWithContext(applicationContext)) {
40-
return
41-
}
42-
43-
var self = this
44-
45-
suspendifyOnThread {
46-
var openedProcessor = OneSignal.getService<INotificationOpenedProcessor>()
47-
openedProcessor.processFromContext(self, intent)
48-
}
49-
50-
finish()
39+
processIntent()
5140
}
5241

5342
override fun onNewIntent(intent: Intent) {
5443
super.onNewIntent(intent)
44+
processIntent()
45+
}
46+
47+
private fun processIntent() {
5548
if (!OneSignal.initWithContext(applicationContext)) {
5649
return
5750
}
58-
59-
var self = this
6051
suspendifyOnThread {
61-
var openedProcessor = OneSignal.getService<INotificationOpenedProcessor>()
62-
openedProcessor.processFromContext(self, getIntent())
52+
val openedProcessor = OneSignal.getService<INotificationOpenedProcessor>()
53+
openedProcessor.processFromContext(this, intent)
54+
// KEEP: Xiaomi Compatibility:
55+
// Must keep this Activity alive while trampolining, that is
56+
// startActivity() must be called BEFORE finish(), otherwise
57+
// the app is never foregrounded.
58+
finish()
6359
}
64-
65-
finish()
6660
}
6761
}

0 commit comments

Comments
 (0)