Mohan C
Mohan C

Reputation: 93

How to start app offline and sync when connection is available

I am working on an Inventory app to run on android. I am planning to use HTML5, JS, pouchdb and couchdb. While I understand that this app after connection to the server, can go offline and work without any connection and sync later, how can I start the app if there is no internet connection?

I tried to use some servers from android play store, but I want to avoid it.

The app should start without any internet connection. Save data locally. Even after quitting, the data should be available and sync when the internet connection becomes available.

Upvotes: 2

Views: 2991

Answers (1)

thau0x01
thau0x01

Reputation: 892

Working offline and then syncing data with online servers may be pretty tricky some times.

Scenarios

The most recommended way to do this without impact your UX is wondering some scenarios in which your app will work, like this:

  • Does your user need to register or login into any service or account?
  • Does your user data need to be previously registered into your online services, before the user can start working with it locally?

Possible Solutions

Try to answer the above questions, before designing how your app will start.

My User need to be registered or logged in an online account before start creating inventories

This says your user must have an internet connection, when he start your app for the first time.

  1. if this is truly, so your app must start at the first time asking for login or register

    • in this case, if there is no connection when the user start the app for the first time. Your App must to stop on a login Screen (this is a commonly used flow)
  2. After user login, you must store user data retrieved from online servers into a local storage

  3. When the user start the app on the next time, app will recognize it automatically and will skip the login/auth screen.

  4. Your App must follow it normal workflow (creating, editing, deleting inventories)

My User don't need to be logged in to create inventories on my app

This answer automatically says that your user data don't needs to be previously registered online, before being modified offline, so no internet needed here, including at the first time the user open the app.

  • In this case, you will just start checking for internet connection and if has internet, you'll ask the user to auth.
  • In this case your app must start with its original workflow, creating all data offline and then, just when user is logged in, it'll try to sync local data with online stored data.

TL:DR

In all of these cases, You're looking for a Progressive Web App, PWA's are web applications which works offline, on the client side.

Upvotes: 4

Related Questions