Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm not sure if I'll be able to properly deal with #974 anytime soon, so here's a not so elegant but simple fix.
This PR should fix a whole slew of
IllegalStateException
s reported in the Play Console. Fixes #975, #784.Using foreground services has some merit for some of the tasks, but #974 still stands.
First commit here makes the app use foreground services for any background tasks. This is technically ok, but Android requires to display a visible notification when the service is running, which is quite annoying (especially because in this implementation the notifications don't have any meaningful content). These notifications may be disabled (using notification channels), but only manually by the user.
According to Play Console the errors are relatively rare, so the app should work fine with non-foreground services most of the time. The second commit tries to use foreground services only when starting a normal service fails. This is debatable.
The simplest way to test it is to enable autosync on app start, and start the app with the screen turned off (like with
adb shell am start -n fr.gaulupeau.apps.InThePoche.debug/fr.gaulupeau.apps.Poche.ui.MainActivity
or directly from AndroidStudio). There's a timeout inMainActivity.updateOnStartup()
though.