I searched a lot, but couldn't find nothing clear. Every solution seems outdated. In my app, I need this simple task: the user can enable a daily reminder and select a time in the Time Picker. Everyday in the selected hour the user should receive a simple notification. I only need to read the local database (Room, SQLite) and then show a notification. I'm using AlarmManager, because the user should receive the notification in the exact time he selected. Everthing is working fine when the app is open or minimized. When I close the app in the recently used apps (swipe up) I don't receive the notification.

I have a class that creates the alarm with this calling:

alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,                 
 calendar.getTimeInMillis(), pendingIntent);

The pendingIntent opens a NotificationReceiver extends BroadcastReceiver class. In the onReceive method I read the db and show the notification. I also tried starting a service in the onReceive method (IntentService or Service) but they work exactly as just using the broadcast receiver.

I put the receiver in the AndroidManifest. Everything is working except when I close the app or restart the system (I registred the BOOT_COMPLETED in the manifest and I have another broadcast receiver that configure the alarm again. If I open the app and keep it open before the notification time, then I receive it. But if the app is still closed, I don't receive it. So I thik the BOOT_COMPLETED is working fine). The other solutions doesn't seem to work. What can I do to have it working on Android 11 (Pixel 3 device)?

One example of what I need is the Google Keep app, but mine is simpler. I don't see any notification dot telling that the Google Keep is running in background. Still, I get the reminders on time. How the Google Keep works? It's a service always running (and killing the battery)? It uses AlarmManager and BroadcastReceiver? WorkManager? Even if a close the app or restart the phone, I always get the notifications. How can I achieve it on my app?

0

There are 0 answers