Skip to content

Conversation

@wantroba
Copy link

This error (#2633) was occurring because applicationContext was null. So I made this change and the problem was solved. I also noticed that the awesome_notifications package does not set applicationContext to null at any time: https://github.com/dokumanx/awesome_notifications/blob/5e0959c57c612ba525a8118dbbfa416f32426d06/android/src/main/java/me/carda/awesome_notifications/AwesomeNotificationsPlugin.java

Please let me know if there is any reason for applicationContext to be set to null. Otherwise, just approve this PR. Thanks

@MaikuB
Copy link
Owner

MaikuB commented Jun 15, 2025

Thanks for the PR. The reason this was originally done was based what I had seen done by multiple major plugins back done to release resources. Even now I still see some plugins do so but some don't either so perhaps this isn't "official" advice

@wantroba
Copy link
Author

Thanks for the PR. The reason this was originally done was based what I had seen done by multiple major plugins back done to release resources. Even now I still see some plugins do so but some don't either so perhaps this isn't "official" advice

It makes sense and the lib works perfectly for all cases except when I need to trigger a notification with the app in the background using the WorkManager lib (error #2633). I believe the resource is being released before the notification is triggered. As the awesome_notifications lib also did not set it to null, I made an adjustment and it solved my problem.

@MaikuB
Copy link
Owner

MaikuB commented Jun 17, 2025

Sounds like you're consistently running into the issue but sounds odd. The reason it is released is when no engine exists and would've expected more members of the community to report this too. I vaguely remember trying both plugins together and not running into this issue either. To confirm, when you use both plugins, do you call the following methods in the top-level/static function that you pass to the workmanager plugin and do so before calling the API to show a notification?

@MaikuB
Copy link
Owner

MaikuB commented Jun 18, 2025

FYI I tried reproducing this myself but periodic tasks don't seem to be working for me in general. I've seen others mention this on the workmanager repo as well. Do you by chance have a link to a repo with a minimal app that can reproduce this? Even when I clone its repo, its example doesn't work with a periodic task. A one-off works though I only did on debug mode. Does one-off with a delay work for you or do you run into the same issue?

@iampato
Copy link

iampato commented Nov 2, 2025

Add this :

 @pragma('vm:entry-point')
  static Future<void> messagingBackgroundHandler(RemoteMessage message) async {

seems to have solved it

@MaikuB
Copy link
Owner

MaikuB commented Nov 2, 2025

Thanks @iampato. I was suspecting this was the cause but was hoping @wantroba would respond with a minimal app. I know the work manager plugin essentially has a helper method that calls WidgetsFlutterBinding.ensureInitialized(). Either way I can't reproduce this and @wantroba hasn't responded for a long time so will be closing this

@MaikuB MaikuB closed this Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants