Background sync in android

Hi,

I am a joplin user. Plan to make a patch to let joplin do background sync in android. I plan to use HeadlessJS of React Native to achive this purpose. The code size will be quite big.

Per guild in source, I need to start discussion in this forum. So I created this topic. If you have any question about it, please ask it.

Regards,
Chen Yang

5 Likes

Have you looked at the previous attempts to implement this and made sure that your solution won't fall foul of the same things?

I don't know there are previous attempts at all. Would you mind help to provide some info about previous attempts? I guess this info is hidden in some place and simply googling is not able to find it.

Just search the PRs or issues for "background sync"

Thanks a lot. Let me take a look first.

After some researching, I am interesting on existing solution provide by @camgraff. Basicly, we use same underly tech: HeadlessJS. The difference is that he uses react-native-background-fetch and my plan is to use headlessjs directly + java code to handle background.

There is a difference is that he aims for android/ios together. And I only works for android. By using native java code, I believe I can achieve the state of art in background sync which I mean I can make background sync as good as other app ( none google app ).

I think this might be a problem in itself, we would want a solution that works for all platforms and wouldn't want to split functionality by OS unless it is literally impossible to do so on that platform.

I am understanding your consent. But let me be honest, you can hardly to find a person can handle both andorid and ios at same time. If you are only interested in total solution, I think you'd wait more time than you expected.

For me, it is ok. I am android user and developer, so I am satisfied with android solution only and willing to spend some time on it. I am writing this post because I hope I can contribute it back to community. However, if it is not possible, I am ok with it.

Thanks,
Chen Yang

I would have to defer to the experts here, it is quite common we get people proposing fixes for things that only target one platform and quite often the answer is that we would prefer to wait for a complete solution than doing half of it.

I'll leave anything else for comment by people who know more about the subject than I do.

1 Like

Agree. @Daeraxa Thanks a lot. You have give really good info about previous codes.

I have complete my first prototype and push code to GitHub - wao/joplin: Joplin - an open source note taking and to-do application with synchronization capabilities for Windows, macOS, Linux, Android and iOS. Forum: https://discourse.joplinapp.org/ branch android_sync. I also upload prebuilt apk to:

Release Release for android background sync at 0103 · wao/joplin · GitHub.

You can try it at your own risk or you can build from source by yourself. It works great for me. I think it is enough for my daily use.

3 Likes

How do you manage to trigger sync in the background? Does your native code somehow calls the js sync code?

As Daeraxa mentioned we generally prefer cross-platform solutions but there's so much demand for this feature that we'd consider it if it's well implemented and reliable.

React native support headless js Headless JS · React Native. By using it, native code can invoke async js function.

Basic idea is that you can register an async function as headless js, then native code can tell react native to run it.

1 Like

This background sync could be disabled by the user ?

Already can be, thats what the disabled sync interval does.

I think current native code in my branch, you can't disable background trigger because it is just a prototype. In finaly PR, I can add a native method to turn off background sync.

Although you can forbid in js code which means even native code trigger sync however it will be bannded due to some js level restriction.

But it is not good for battery.

1 Like

That would mean a button to completely quit the app will be needed to be sure the app stop working in the background ?

In android, as I understand, there is no such concept "quit the app". The lifecycle is manager by system/os not by app itself. However, for your question, I think when in settings UI, user choose no auto sync then js code can call the native module method to stop the app be triggerred future in background by andorid.