0

I have a foreground service which is basically used for counting down from certain number.

As 1 foreground service can have only 1 notification, I show other notifications using notification manager, and update content after each second. Problem is notifications are shown all, but after 2 or 3 seconds, let's say if 5 notification shown, only 2 of them are being continued to update, remaining 3 are not updating

In docs it says that rate is applied to noticication updating, but I can see samsung clock app can update its notifications (only 3 of them can be shown at a time)

Any way to solve this?

private fun startCounterService() {
    ServiceCompat.startForeground(
        this,
        100,
        getNotification(0),
        ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
    )
    startCountDownTimer()
}

private fun startCountDownTimer() {
    timerJob?.cancel()
    currentNotificationIds.forEach { showNotification(it, 9) }
    timerJob = CoroutineScope(Dispatchers.Main).launch {
        var counter = 0
        while (true) {
            currentNotificationIds.forEach { showNotification(it, counter) }
            delay(1000)
            counter++
        }
    }
}

private fun showNotification(id: Int, counterValue: Int) {
    notificationManager.notify(id, getNotification(counterValue))
    currentNotificationIds.add(id) // this list is a set of ids
}

private fun getNotification(counterValue: Int): Notification {
    return getNotificationBuilder().setContentText("Counter value is now: $counterValue").build()
}
0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.