How to make an app that keeps working offline

19 views
Skip to first unread message

Rubén V

unread,
Sep 19, 2020, 12:03:43 PM9/19/20
to CodenameOne Discussions
Hi,

I have a street sales project that has to continue working when the data signal is low or does not exist.
I count at least 10 tables that I have to access from my webservice and many handle high volume (for example: "price list").
I read the "Automatic Caching" blog and find it great. However, I have a hard time implementing it. Do you have any example code that allows me to guide myself on the subject?

Regards

Shai Almog

unread,
Sep 20, 2020, 1:22:43 AM9/20/20
to CodenameOne Discussions
Hi,
working offline is pretty complex. I would suggest creating a local DB that mirrors the one within the webservice. You would then need to create an update strategy that periodically refreshes the DB based on updates in the server.
For submitting operations done locally you would need to use something like a command patterns that classifies an action as "Pending" until the server approves it. Then when networking is available you need to try submitting an order and fail gracefully for the case of server failure.

I think the caching related features aren't really useful for your case as you need to actually write the business logic related to database replication and merging. It isn't rocket science but it's still a bit challenging.

Dave Dyer

unread,
Sep 20, 2020, 8:00:34 PM9/20/20
to CodenameOne Discussions
I thought along the same lines, but Shai has really nailed the idea.  I'd add one thing;  DO NOT write two sets of code, one for
working online and a fall back to use when offline.  Structure your code to always use the same cycle - update local database,
record "pending" transactions, post pending transations to the real server.
Reply all
Reply to author
Forward
0 new messages