1

I am writing a reminder app which has the following use case:

  1. The user sets up a reminder for hour A.
  2. The user sets up a reminder for hour B.
  3. Hour A arrives and the reminder notification pops up. The user does NOT dismiss it.
  4. Hour B arrives and the reminder notification pops up. Two notifications are on the status bar at that moment.

Until now, I was using:

notificationManager.notify(
    alarmId,
    Notification.Builder(context, Constants.PRIMARY_CHANNEL_ID)
       .setSmallIcon(R.drawable.idle_1)
       .setCustomContentView(remoteViews)
       .setOngoing(true)
       .setContentIntent(notifyPendingIntent)
       .setAutoCancel(false).build()
)

Without a problem, but apparently Xiaomi kills notifications when the app that threw them gets removed from recents. This would be a critical error for all Xiaomi devices using my app; so I tried using a ForegroundService and applying this.

The problem is using a ForegroundService is not intended for handling multiple notifications: if two reminders start the service, the most recent reminder notification will kill and replace the earlier one. (As explained in this answer). Can you see the loop I'm trapped in?

My ForegroundService is no big deal, it worked perfectly when I tested it but it has the notification replacement thing.

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
    super.onStartCommand(intent, flags, startId)
    // ...
    startForeground(alarmId, notification)
    return START_STICKY
}

At the moment I'm completely stuck: am I missing something or should I just ditch the huge market share Xiaomi phones have due to this? Thanks in advance!

xvlaze
  • 837
  • 1
  • 10
  • 30

0 Answers0