MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.45k stars 1.39k forks source link

Android: Scheduled Notification Doesn't Appear After Restart + Relaunch App #2412

Open jcmtyler opened 4 days ago

jcmtyler commented 4 days ago

Describe the bug I create a notification using zonedSchedule() and I can see it getting triggered while the app is running after I create it, or after I restart the device (Pixel 5 emulator API 33). However if I restart the device and then relaunch my app, then the notification does not appear. I can see that it's still there both by calling pendingNotificationRequests() and viewing the scheduled_notifications.xml file in shared prefs. If I restart the device again, then the notification will appear. I have reproduced this using my own code and also the sample app from flutter_local_notifications 17.2.2.

To Reproduce

  1. Android emulator running Pixel 5 API 33
  2. Launch the flutter_local_notifications sample app
  3. Changed line 1448 in _zonedScheduleNotification() to create a notification 5 minutes after now (also change buttonText on line 432 to say 'appear in 5 minutes')
  4. Tap button 'Schedule notification to appear in 5 minutes based on local time zone'
  5. Verify that the notification has been saved by tapping 'Check pending notifications' or viewing the scheduled_notifications.xml file
  6. Restart emulator by swiping down from the top twice, tapping the power icon, and then Restart
  7. After restart, launch the sample app
  8. Wait for more than 5 minutes to have elapsed from creating the notification
  9. No notification appears
  10. Verify that the notification still is pending by tapping 'Check pending notifications' or viewing the scheduled_notifications.xml file
  11. Restart emulator again as in step 6
  12. Notification will appear after startup, before launching the sample app

Expected behavior On step 8 above, I expect the scheduled notification to appear after restart, regardless of whether the app is in foreground or background, or whether it's been launched after restart.

Sample code to reproduce the problem I have reproduced this using the flutter_local_notifications sample app, v17.2.2, running on a Pixel 5 API 33 emulator.

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.24.0, on macOS 14.6.1 23G93 darwin-arm64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.4) [✓] Chrome - develop for the web [✓] Android Studio (version 2024.1) [✓] VS Code (version 1.92.1) [✓] Connected device (4 available) [✓] Network resources