File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed
widgetssdk/src/main/java/com/glia/widgets Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import com.glia.widgets.R
10
10
import com.glia.widgets.core.notification.NotificationFactory
11
11
import com.glia.widgets.core.notification.NotificationRemovalService
12
12
import com.glia.widgets.core.notification.areNotificationsEnabledForChannel
13
+ import com.glia.widgets.helper.Logger
14
+ import com.glia.widgets.helper.TAG
13
15
14
16
internal class NotificationManager (private val applicationContext : Application ) : INotificationManager {
15
17
private val notificationManager: NotificationManager by lazy {
@@ -88,7 +90,12 @@ internal class NotificationManager(private val applicationContext: Application)
88
90
override fun startNotificationRemovalService () {
89
91
// If this service is not already running, it will be instantiated and started (creating a process for it if needed);
90
92
// if it is running then it remains running.
91
- applicationContext.startService(Intent (applicationContext, NotificationRemovalService ::class .java))
93
+ try {
94
+ applicationContext.startService(Intent (applicationContext, NotificationRemovalService ::class .java))
95
+ } catch (error: Throwable ) {
96
+ // Above code is known to throw an error if app is in background
97
+ Logger .e(TAG , " Failed to launch 'NotificationRemovalService'" , error)
98
+ }
92
99
}
93
100
94
101
override fun removeCallNotification () {
Original file line number Diff line number Diff line change @@ -252,13 +252,17 @@ internal object Dependencies {
252
252
chatBubbleController : ChatHeadContract .Controller
253
253
) {
254
254
lifecycleManager.addObserver { _, event: Lifecycle .Event ->
255
- if (event == Lifecycle .Event .ON_STOP ) {
256
- chatBubbleController.onApplicationStop()
257
- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .S && Glia .isInitialized()) {
258
- notificationManager.startNotificationRemovalService()
255
+ when (event) {
256
+ Lifecycle .Event .ON_PAUSE -> {
257
+ // Moved to on pause due to "IllegalStateException: Not allowed to start service app is in background"
258
+ // Related bug ticket MOB-4011
259
+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .S && Glia .isInitialized()) {
260
+ notificationManager.startNotificationRemovalService()
261
+ }
259
262
}
260
- } else if (event == Lifecycle .Event .ON_DESTROY ) {
261
- chatBubbleController.onDestroy()
263
+ Lifecycle .Event .ON_STOP -> chatBubbleController.onApplicationStop()
264
+ Lifecycle .Event .ON_DESTROY -> chatBubbleController.onDestroy()
265
+ else -> { /* no-op */ }
262
266
}
263
267
}
264
268
}
You can’t perform that action at this time.
0 commit comments