Skip to content
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

Wrap notification updates in try catch to avoid errors #199

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

rtibbles
Copy link
Member

This seemed like the simplest way to handle these errors and stop them from breaking job execution, in local testing on a low powered Android 9 device, I confirmed that the errors were properly caught, and that tasks continued to run successfully. Also, notifications did not pile up and were properly cleared, in spite of errors.

Manager manager = new Manager(ContextUtil.getApplicationContext(), ref);
manager.send(notificationTitle, notificationText, progress, total);
try {
Context context = ContextUtil.getApplicationContext();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this was where the context issue was originating from then it probably has to do with removing the worker reference from this utility in combination with using some non-RemoteListenableWorker workers. Since the non-RemoteListenableWorker workers would be started by the system, we wouldn't necessarily have access to the foreground service. Storing static instances of the worker is bad, not only for the reasons regarding the context, but also because multiple instances could be running at once, so you don't necessarily get the instance you expect.

An alternative would be to go back to having all workers be RemoteListenableWorkers. Or use a sort of context manager approach in the worker such that this utility returns that context when called within that block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge this regardless. I added a follow up issue

@bjester bjester merged commit 979866f into develop Feb 12, 2024
5 checks passed
@rtibbles rtibbles deleted the catch_notifications_if_you_can branch February 12, 2024 21:16
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