How to constantly update offline android database through online database? - android

I'm planning to create an android app for customers(shop) that have an offline database so the users can use it offline. After that I will create a Website for the owner of the shop so he/she can post new items on the website then save it to the online database. My question is how can I constantly update the offline database of the android app whenever there's is a new item on the online database? Any suggestion or theory that I can use will help me a lot. I'm new in android and web sorry.

What I personally did for one app was that I updated my device database whenever the user went online. I saved the current database version using SharedPreferences and then the app checks the servers' database version -- which was saved in a text file for easy reading and parsing by the Android Device. If there's a mismatch, the device downloads the database update, essentially performing a sync process. It downloads the entire database (if done properly, it shouldn't be too much) and photos if need be.
Basically what happens is that your app will check (once it goes online) if there's a database update available.

this link might be helpful sync remote mysql db to sqlite

Just save a time stamp on the device of when was the last time the offline database was updated.
Do the same each time for the online database - each time the user adds something from the web, just save a time stamp.
So, when you launch the application, just compare the two time stamps. If the time stamp of the online database is greater than the one on the device - sync the new items.

Related

How to alert users on new update to local database?

I'd like to receive some advice from all of you.
What is the best way for me to alert users on an update to my app? My app is a very knowledge-based & it works like a dictionary, so there will always be updates to it.
The database I have used is by DB Browser for SQLite, and they are all local database where it is uploaded into the assets folder in Android Studio.
Currently, the limitations are that:
1) it's obviously not real-time because it's stored locally;
2) every update I make to the database structure, I am required to upload the new database into the assets folder again, followed by uninstalling the old app on my phone, then run the app to install in my phone again so that the new database is overwritten.
I have read (How can I regularly update a database of content on an Android app?) & some others, and it seemed like I have to have a server, a cloud-based database & live app in market, to solve the limitations?
Is there really no way for me to overcome the limitations if I want to stick to a local database? At the same time, I kinda wish to avoid setting up a server because I am not intending to make the app live on market, and also this is just a school project I am working on and as such, I have very limited skill sets & knowledge about it and would like to make it on a school-project-based level.
Thanks in advance.
One way to do it is to connect to your local DB through local network instead of assets folder. Therefore, you can update the information by querying the local DB.
As for syncing the information between DB and your application, you should create a trigger or watcher that notify your application when the DB is updated. Therefore, your application can know when to query the DB for the updates. Another way is to just query the database periodically.
Bonus: you could move your database to a cloud-based database. Usually there are several providers that provide free database hosting up to a certain size, which should be enough for your project.

Best practice(Architectural level) to implement syncing the data back and forth from sever to android [duplicate]

This question already has answers here:
Synchronizing client-server databases
(6 answers)
Closed 6 years ago.
I've a Server application running with data storage in MySQL.
Later some time, we happened to build a simple Android app for data updation to the server. So far so good.
But, Since with the issues we've been facing with network connectivity often, We wanted to maintain the data completely offline during poor network connectivity and sync it when there is proper network.
1) How I'm doing this is, Let's say if we have five tables in MySql from the server side, Then same tables with same structure I've build in SQLite in my Android App so that the user should able to use the app as if theresn't any difference. I've an additionlal independent table added in SQLite for offline updates which has to be synced.2) Everytime I login into the app with proper network, I'm truncating all the tables in SQLite and fetching new fresh data from server and storing. So here, between login and landing page, since server has much data, data fetching and storing taking a lot of time in the app. Here I don't know any other way to achieve the performance.
So Here considering the above points, Is there a better way fetch the data from the server and sync with existed database in SQLite rather than truncating and restroring all the data from server?
I've been looking for the solution so eagerly. Please can someone helpout with good explanation or reference?
This is how I do it in my app:
store the last successful sync date on the device
every object has a lastUpdated column
deleted objects are not really deleted. They have a isDeleted flag
sync all objects that have a lastUpdated >= your last sync date

Firebase Database offline writing

In my Android app I have to keep an existing SQLite database, but in order to sync elements (tasks from a todo-list) to multiple devices I decided to use Firebase Database.
So I'm not enabling Firebase Database offline mode, since I have to use SQLite for that (it's for a college project).
So what I'm doing for writes is that, whenever some data gets added or removed from the local SQLite database that change is also made to the Firebase one.
All this works as expected if the user is connected to the Internet, or even if the user adds a task offline and then becomes online while being on the app.
But if the user adds a task offline, then closes the app and then becomes online in another app, the change doesn't get pushed to the database, even if the user opens my app again.
Any ideas?
Thank you.
As you did not enable the Firebase Database offline mode all data your app trying to push are not saved in persistent storage, only in memory. Thats why all these data are not pushed to Firebase after application restart.
So you need some synchronization algorithm at application startup which pushes data from you local database to firebase (and vise versa).
For example, you can use timestamp marker (System.currentTimeMillis()) in both local and firebase side which always should be updated on any database change.
Then at application startup you can just check this marker:
if local marker is greater than the remote one - that means that
remote database is outdated. So just copy all your local sql database
data to firebase.
if remote marker is greater than the local one - just clean local db
and download all data from firebase.
if both markers are equal - that means that everything is up to date,
do nothing.
Hope this helps :)

android sqlite update online with updating the app and affecting user inputted data

I using SQLite as my database.
Using the app, the user can save some item on the database.
But I would like also to update the database from time to time.
The problem is how can I update the database without affecting the user inserted data and in a manner that it will download the new database online and not by updating the app itself.
Since my comment is large, I'll post it as an answer.
You won't find any tutorial showing exactly what you're trying to accomplish, because what you need is somewhat complex (but not difficult)
First approach:
You need your app to query some webservice to find out if there's a newer version of the database, and if there is, download it
The database must be saved in some temporary location, then you transfer all the users saved data to the new database, and finally replace the apps database with the new database (already updated with user's data)
Another approach would be:
Make your app query some webservice to find if the database needs to be updated.
If yes, download the SQL commands to modify the database structure.

Android: Updating local database from an online database

I have an android application that works as an inventory application to different stores (You can search for any electronic device according to certain specs and find which stores sell it and their location). The application comes with a local database, this database needs to get updated through a soap service to have the latest information about the electronic devices, offers and shops. The soap service will get it's data from another database hosted on the web and that gets updated from different sources through a designated website.
The problem we are facing is that we can't figure out the way to update the local database without having the user downloading the whole "online" DB from the web every time it gets updated as that would be bandwidth consuming an the DB can get as big as few MegaBytes.
We came up with the following solutions:
Create Versioned Update Scripts that will have the SQL transactions done on the online DB, the application will download them and run them to update the Local database. The issue with this solution is that if a user doesn't update the application regularly, they will have to download alot of scripts to do the update the next time they are going to update the application, and most likely it will contain a lot of junk scripts (Items get added on an early script, then gets deleted on a later on) .
Download the online DB and replace the local one with it. As mentioned above this can be pretty annoying since the DB size might be a few Megabytes.
Can someone help me with this issue?
TYI
Your best bet would be Google Cloud Messaging for Android (GCM)
http://developer.android.com/guide/google/gcm/index.html
It doesnt get any better than this. This video should get you up and running in no time dude.
http://www.youtube.com/watch?v=51F5LWzJqjg

Categories

Resources