[Solved] How can I use the offline capabailities of Firebase database?

Hello,

Is it possible to use the offline capabilities of Firebase Realtime Database? What are your recommendations if I want my app to work offline and sync automatically when the user goes online.

Thanks,
Marco

1 Like

You would need to check if the device has an internet connection (there’s a block for that) and if FALSE then store the data to the device using the local storage component. You can check for internet at specific time intervals using a timer OR after the user has pressed a certain button(s). If internet connection is TRUE then you would call the data from the local storage and save it to your Firebase like normal. The offline feature like in classic is no longer available with X.

2 Likes

Got it. This is what I’m ding already. I was hoping there’s a better way with less blocks. Thanks!

No problem. Just make sure you mark this topic solved please.

Hi guys,

I’m new on Thunkable and I don’t understanding it very well. Do you have any example of simple project working with this function (offline and sync with internet)?

@samclever
@maptheunknown

Hey Andre,

I don’t have a simple project unfortunately but what I do is:

  1. I save all my data in a local storage. I create objects and lists and lists of objects then store it as local storage. This way all the data can be accessed by the user offline. Also with local storage, the data is persisted even if the user closed the app or reinstalls the app. LocalDb doesn’t persist but is also useful if you just need the data for 1 session. Local storage is slow and localdb is fast. So just decide which would be best for you depending on your use case.
  2. Then when the device is online, I call the a function that syncs all my offline data to Firebase. I coded this all manually meaning I have a sync function for each local storage. I have a flag for each object so I know if it’s already synced and when wS it last synced to Firebase so when I iterate to my objects and lists, I know which ones I have to save to Firebase.

I hope this helps.

1 Like

Hi @maptheunknown,
Thank you for reply, it helped me a lot.

In my case, the best way is local storage. I did:

  • save in local storage;
  • get data from local storage;
  • identify if the mobile is off or online;
  • save data in firebase;

I still needing help to auto sync when get online. Could you please help on that? Can you show me how to do this manually? How can I test this offline (only publishing on store)?

On start of my first screen I check if the device is online. If device is online, I check all of my local storage if it’s synced to the cloud then if not yet synced then I save it to firebase manually one by one.

Does that answer your question?

Hello,

If I would like to chane the local DB without thunkable, how can I do it?
Is there a file in the .apk in order to change it?
Thanks,

No. Also, that’s a lot of work to decompile and recompile am apk. Why not just update in thunkable and re download a new version?