Closed AndroidDeveloperLB closed 3 years ago
This has since been fixed.
@keyboardsurfer Seems fine now. May I ask if indeed a foreground Worker is the perfect replacement to IntentService? I want to run something in the background (with foreground notification if the app isn't in the foreground) right away, with a queue.
With Developer Preview 1 of Android 12 we introduced the concept of expedited jobs. We recommend to use WorkManager for this as well and have a sample available.
And yes, we recommend using WorkManager for your intended use case.
@keyboardsurfer I've noticed some problematic issues with WorkManager though, when trying to migrate from IntentService :
It offers foreground option (using foreground service, probably), but I wonder if there is a way to show/hide the notification of the foreground operation (automatically), based on when it's possible and needed. Meaning that if it sees it's possible without a notification (example is when the app is already in the foreground), don't use it. Or when the user left the app but it needs to continue, or came back to the app (and so the notification can go away). Not to mention that sadly starting from some Android version, even if you have a very short foreground service operation, the notification will appear for much more than it. I think on Android S it changed, but still: WorkManager is supposed to be for a wide range of Android versions. All of these I could kinda do with IntentService. If WorkManager is the perfect replacement, so much that IntentService became deprecated, it should allow this too, either manually or automatically (or both).
As opposed to IntentService (and even JobScheduler, that WorkManager uses), it can cause really weird issues with AppWidget, and Google doesn't even confirm it as a bug, saying that it's expected (WorkManager with AppWidget? What's the connection between them, that one could damage the flow of the other?), and that as a workaround (they therefore admit that we need a workaround) we should always have a pending job: https://issuetracker.google.com/issues/115575872 https://commonsware.com/blog/2018/11/24/workmanager-app-widgets-side-effects.html (see what CommonsWare has to say about this too).
When people asked for better alternative to a workaround (even just an optional feature to disable this behavior by disabling the optimization), it was also denied: https://issuetracker.google.com/issues/119920965
That's while having 0 documentation about the issue anywhere, on both the websites of Android and on the IDE. I've spent hours on this, thinking it was my fault in using WorkManager (or app-widget) the wrong way, not understanding why the app-widget suddenly refreshing more often than it should.
So what exactly is so good about WorkManager that it was chosen to be the the perfect replacement? And why IntentService was deprecated?
@keyboardsurfer
/* Remove this comment
Reporting an issue with the Architecture Components or the samples? Yes
Question about Architecture Components?
No.
Bug report or feature request for Architecture Components?
Bug report.
Before filing a new issue, please check if it is listed in the Release Notes or reported in the issues list.
Issue with the samples?
Yes!
Please add the sample name ("all", "GithubBrowserSample", "BasicRxJavaSampleKotlin", etc.) and include it in the title if it applies. WorkManagerSample
WorkManagerSample.zip
Why so many questions of the same type for a simple thing?
I try to open the sample, and it can't be built:
Android Studio 4.2 Beta 4 Build #AI-202.7660.26.42.7094744, built on January 21, 2021 Runtime version: 11.0.8+10-b944.6842174 amd64 VM: OpenJDK 64-Bit Server VM by N/A Windows 10 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 4000M Cores: 12 Registry: external.system.auto.import.disabled=true, ide.settings.move.mouse.on.default.button=true, debugger.watches.in.variables=false Non-Bundled Plugins: String Manipulation, org.jetbrains.kotlin, com.google.mad-scorecard, org.intellij.plugins.markdown