# Android: A started synchronization should finish, even if the app is in the background

**URL:** <https://discourse.joplinapp.org/t/android-a-started-synchronization-should-finish-even-if-the-app-is-in-the-background/24931>\
**Category:** Features\
**Created:** [6 April 2022 17:37 UTC](https://discourse.joplinapp.org/t/android-a-started-synchronization-should-finish-even-if-the-app-is-in-the-background/24931 "2022-04-06T17:37:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jovial-dubinsky](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/jovial-dubinsky/32/13414_2.png) [@jovial-dubinsky](https://discourse.joplinapp.org/u/jovial-dubinsky)\
**Post date:** [6 April 2022 17:37 UTC](https://discourse.joplinapp.org/t/android-a-started-synchronization-should-finish-even-if-the-app-is-in-the-background/24931/1 "2022-04-06T17:37:22Z")

</div>

Hello!

I recently noticed that once a synchronization has started, it only finishes if Joplin is in the foreground (the currently active app).

Let me explain:

1. Start the Joplin Android app (synchronization starts automatically)
2. After a few seconds open up any other app before the synchronization is done
3. Go back to Joplin and see that the before started synchronization was stuck while the app was in the background

Almost every time I open up Joplin on Android I see something like **4219s** in the lower left corner. In my opinion, a started synchronization should finish and not halt only because Joplin is in the background. I didn't cancel it, so I expect it to finish. Synchronization can take a long time, and I don't want to wait for it to finish before I can open up another app.

This should be something Android is easily capable of. It's just an idea, but I think it would be a nice addition to the app and increase UX noticeably 🙂

Have a nice day.

---

<div class="post-metadata">

**Author:** ![Daeraxa](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/daeraxa/32/6172_2.png) [@Daeraxa](https://discourse.joplinapp.org/u/Daeraxa)\
**Post date:** [6 April 2022 18:45 UTC](https://discourse.joplinapp.org/t/android-a-started-synchronization-should-finish-even-if-the-app-is-in-the-background/24931/2 "2022-04-06T18:45:12Z")

</div>

Its a well known and old issue/limitation seemingly related to react-native. Only real workaround for the moment are to use a "keep awake" app or similar built in function on the phone.

> <https://github.com/laurent22/joplin/issues/3872>
>
> There are various issues (\[1\](https://github.com/laurent22/joplin/issues/727), \[…2\](https://github.com/laurent22/joplin/issues/1029), \[3\](https://github.com/laurent22/joplin/issues/1501), \[4\](https://github.com/laurent22/joplin/issues/1645), \[5\](https://github.com/laurent22/joplin/issues/3671), …) and threads (\[1\](https://discourse.joplinapp.org/t/android-background-sync-interval/1746), \[2\](https://discourse.joplinapp.org/t/automatic-sync-on-phone-app/3056)) on it but it's still not clear to me what exactly is technically not possible to implement.
> 
> \[This comment from September 2018 says\](https://github.com/laurent22/joplin/issues/727#issuecomment-418877957):
> 
> \> Cannot currently be fixed due a limitation of the underlying framework
> 
> Which might be true but that's what libraries are for, right? Therefore this is a \_very\_ misleading comment.
> 
> And \[this comment from October 2019\](https://discourse.joplinapp.org/t/automatic-sync-on-phone-app/3056/8) claims:
> 
> \> we rely on existing libs, which for now don’t exist on React Native
> 
> But it doesn't mention \_which\_ exact libraries would be needed. The logic for syncing is obviously already there. So in theory only the support for doing exactly this sync in a background task would be needed.
> And there are libraries for react-native that are doing exactly this since a few years. For example
> \* \[\`react-native-background-fetch\`\](https://github.com/transistorsoft/react-native-background-fetch) for Android & iOS (first version from August 2016)
> \* \[\`react-native-sync-adapter\`\](https://github.com/ferrannp/react-native-sync-adapter) using the Android SyncAdapter (first version from April 2017)
> \* \[\`react-native-background-task\`\](https://github.com/jamesisaac/react-native-background-task) again for Android & iOS (first version from February 2017)
> \* \[\`react-native-background-job\`\](https://github.com/vikeri/react-native-background-job) for Android (available since December 2016)
> 
> As you can see, these libraries are much older than this comment. So again this would be wrong and a false statement in case this comment refers to syncing libraries.
> 
> Also there's \[this comment from June 2019\](https://github.com/laurent22/joplin/issues/1645#issuecomment-500384473)
> 
> \> Most likely not possible. Android phones these days have services that kill off apps that aren't used, whether you want to keep them running or not. https://dontkillmyapp.com/
> 
> Well,
> 
> 1. it only affects certain vendors in an extreme way. Not every phone is affected.
> 2. \_The exact same website\_ you mentioned shows some workarounds for this very issue.
> 3. Apps are usually killed after a while — not immediately. So Joplin could probably still sync for a while until it would be killed.
> 4. Some FOSS apps which are showing notifications while they are running doesn't seem to be affected (or at least doesn't be to seem affected so often). For instance \[DNS66\](https://github.com/julian-klode/dns66) or \[personalDNSfilter\](https://github.com/IngoZenz/personaldnsfilter).
> 
> So also this comment is false / misleading since the already mentioned website also explicitly mentions workarounds.
> 
> I would obviously understand if the issue would only be the lack of people working on this. In that case this issue could be kept open for tracking, avoiding duplicates and having the possibility to show this issue for possible contributors, so that they know what's still open.
> 
> But currently the given comment are at least somehow lacking some information (or even not relevant / true).
> 
> Thus it would be great if someone could clarify what's really missing here.
> 
> \*\*PS:\*\* Thank you for your work!

---

<div class="post-metadata">

**Author:** ![entrymaster](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/entrymaster/32/13086_2.png) [@entrymaster](https://discourse.joplinapp.org/u/entrymaster)\
**Post date:** [6 April 2022 19:02 UTC](https://discourse.joplinapp.org/t/android-a-started-synchronization-should-finish-even-if-the-app-is-in-the-background/24931/3 "2022-04-06T19:02:02Z")

</div>

I feel this can be accomplished using Headless JS as provided by RN. It can be used to run tasks in JavaScript while app is in the background.  
Alternatively `BackgroundFetch` by `expo-background-fetch` can be used with TaskManager native API for pushing sync in the background.

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [6 April 2022 19:05 UTC](https://discourse.joplinapp.org/t/android-a-started-synchronization-should-finish-even-if-the-app-is-in-the-background/24931/4 "2022-04-06T19:05:27Z")

</div>

Yeah, it can technically be done, it's just extremely non-trivial

---

<div class="post-metadata">

**Author:** ![Medullitus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/medullitus/32/19316_2.png) [@Medullitus](https://discourse.joplinapp.org/u/Medullitus)\
**Post date:** [14 April 2024 11:19 UTC](https://discourse.joplinapp.org/t/android-a-started-synchronization-should-finish-even-if-the-app-is-in-the-background/24931/5 "2024-04-14T11:19:13Z")

</div>

Hey. Could you open a guide explaining how to do this?

---

<div class="post-metadata">

**Author:** ![Medullitus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/medullitus/32/19316_2.png) [@Medullitus](https://discourse.joplinapp.org/u/Medullitus)\
**Post date:** [14 April 2024 11:19 UTC](https://discourse.joplinapp.org/t/android-a-started-synchronization-should-finish-even-if-the-app-is-in-the-background/24931/6 "2024-04-14T11:19:28Z")

</div>

> [@roman\_r\_m](#):
>
> Yeah, it can technically be done, it's just extremely non-trivial

I wish you wouldn't consider it extremely unimportant to mention the reason when making a claim, but rather share your knowledge with us.
