Skip to content

Don't set applicationContext to null onDetachedFromEngine #2634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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?

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.

2 participants