MaikuB / flutter_local_notifications

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

Random crashing behavior on Android, and crashing after system restarts all apps #2446

Open leaf-node opened 1 week ago

leaf-node commented 1 week ago

Describe the bug

App randomly crashes every few hours, or crashes when trying to start it after the app is stopped by the system following app optimization. My app is using a foreground service notification that at least some of the time may be persisting when the app and its background process gets closed by the user.

Tested on Android 15 with 34 target SDK with flutter_local_notifications 17.2.4.

To Reproduce

  1. Upgrade GrapheneOS version
  2. Reboot phone
  3. Wait for apps to optimize
  4. Press GrapheneOS notification to restart apps
  5. Start app manually
  6. It crashes

Crashing also occurs randomly every few hours. I started noticing this issue in the last few days, about a week after I upgraded dependencies for my app, including this module from version 17.2.3 to 17.2.4.

Expected behavior

The app shouldn't crash.

Sample code to reproduce the problem

I don't have source code available for this yet, hoping that it's an easy bug to solve. If not, please let me know, and I'll consider creating a basic app with this problem. Thanks!

Crash Logs

type: crash
osVersion: google/shiba/shiba:15/AP3A.241005.015/2024110400:user/release-keys
flags: dev options enabled
package: com.example.foo:1, targetSdk 34
process: com.example.foo
processUptime: 92 + 323 ms

java.lang.RuntimeException: Unable to start service com.dexterous.flutterlocalnotifications.ForegroundService@c4128db with null: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.Serializable android.content.Intent.getSerializableExtra(java.lang.String, java.lang.Class)' on a null object reference
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5199)
at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2478)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8744)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
at com.android.internal.os.ExecInit.main(ExecInit.java:50)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:369)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.Serializable android.content.Intent.getSerializableExtra(java.lang.String, java.lang.Class)' on a null object reference
at com.dexterous.flutterlocalnotifications.b1.a(SourceFile:1)
at com.dexterous.flutterlocalnotifications.ForegroundService.onStartCommand(Unknown Source:10)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5181)
... 11 more
leaf-node commented 1 week ago

Using version 18.0.0 of flutter_local_notifications seems to prevent the random crashes that were also occurring with similar stack traces. Hopefully this also resolves the issues with starting the app after automatic app restarts.

leaf-node commented 1 week ago

I'm still getting this on version 18.0.0.

leaf-node commented 6 days ago

I'm also seeing this on the 17.2.3 version of the library, but I don't recall this error before, so it's possible that the crashing behavior could be due to a bug in my code.