Migrate Sync from Async task to Foreground Service.
I would like to propose the idea of doing all the work required to sync deck in foreground service instead of using async task.
Foreground Service: It is type of service which is used to run a particular task in background. For more:- https://developer.android.com/guide/components/foreground-services Current code: https://github.com/ankidroid/Anki-Android/blob/2cd449e284f4271b6e1541577fb493b519f0c8d2/AnkiDroid/src/main/java/com/ichi2/async/Connection.java#L343
I agree with @prateek-singh-3212, syncing with a remote server is something that can run as a Foreground service because it interacts with UI and we want the user to control syncing process and cancel anytime he/she wishes.
Anyone wishing to read more about, here is a nice guideline by Android team. https://developer.android.com/guide/background#choosing_the_right_solution_for_your_work
It's more important than that actually: we want the first syncs - which take a long time and are a real pain point for users, to sync media (the slow part of the sync) "in the background" (that is, without locking the UI, but without stopping the sync) after the collection is in sync (which is fast). The only way to have a long-running task continue running regardless of UI state is a foreground service (and even then some vendors kill you: https://dontkillmyapp.com)
stated differently, this is vital to have reliable media syncs on current android versions
Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically
I require the complete plan.
By mike- url
This is an area of lots of work with regards to using more rust code directly - just wanted to mention that - specifically check PRs filtered by user dae and see how sync works with V16 schema enabled via development options, it's quite different but working well,
Added label. I will look in this after completing GSOC work
Wanted to chime in that this is a pain point. I just signed up and got a shared French deck with 5k words, and it took 4 or 5 attempted syncs until all of the content was uploaded to AnkiWeb, with each sync running for a few minutes. Not sure if that's a common use case.
When I downloaded Anki desktop and logged in, it was really fast, like less than 10 seconds. But the process wasn't the same (it was downloading rather than uploading decks).
Kind of duplicate of the issue to improve sync UX with the new backend, which should use a foreground service