Search code examples
androidkotlinbroadcastreceiveralarmmanagerandroid-pendingintent

Best way to reset pending intent in background after reboot in Android 2021


I'm building a reminder app. And when reboot the device, the alarms already have been set as pending intent in alarm manager is destroyed. So when reboot:

  1. Wake broadcastReceiver
  2. BroadcastReciever calls an Activity
  3. This Activity sets pending Intent again.

It worked well. However, I used an Activity, so this Activity shows up on the display a second after reboot. That's not really good. So I want to make this work on background.

Then, I noticed I can use IntentService. However, IntentService is deprecated in API level 30. Also JobIntentSerive is deprecated too.

I'm very confused. What should I use to make this work on background? Thank you.


Solution

  • You can reset the alarms directly in the BroadcastReceiver called at boot time. You don't need to launch any other components to do this.