I'm developing an Android app I want to publish on Google Play that shows data from its internal database.
I'd like to insert new data in the app internal database once a day for the next n years, this operation should be done automatically from a program that scrapes the internet for new information.
So, when a user opens the app on his mobile, the app internal database has to be updated with the new data, if there is (without have to update the whole app).
Is there a solution?
Without a database on a server
I will outline my proposed architecture for your problem:
You should have a server with a database that will hold all your data and an api endpoint for the android client to get the updates. Something like
http://yourhost/get_updates?since=13435465345.
Then the server should use the 'since' param to query for data updates, something like
select * from news where updatedAt>:since
The server will generate a responce based on that query in your favorite format (json or xml) and return it to the client. The client will take the data and insert it in the local database, and store the current timestamp as an update point (to use is as future 'since' param)
Related
I am developing an Android application to collect the store (Grocery) information.
The application have modules to create store, set it's attributes like address, lat lng, operating hours, manager details, building photos, etc.
Once the store is created user need to list down the assests of that store by clicking photos and providing it's details.
To store all this details, i have around 15 SQLite tables.
Now i want to implement feature of 'Synchronization', all this captured details need to send to server whenever connection is available otherwise detail should be stored locally and whenever connection is available it should move to server.
Also, please note that the number of tables may increase up to 40 as application grows.
I searched for the solutions/approaches for this on Google but in most of the article or example they have mentioned for small scale application having small data.
I have also implemented synchronization feature for small datatable (2 tables), where i checked for last updated timestamp on server and local and if it's different then we synchronize the data. I don't this i should use this approach for such large scale and large database.
I have one approach which doesn't depend on numbe of tables.
I am planning to have single table which store the following data
id
URL
request header
request body
Now let's say connection isn't available while sending request so it will be stored in table. Whenever connection is available it start reading the table and execute the request, on success it will remove the entry from table. With this approach we need only one table in SQLite.
The problem with this approach is when we want to retrieve data offline how we can do that? Do we need to have local database schema same as server?
Please guide.
Thanks
If you are syncing data with a server and you are removing local storage data ,which is incorrect as per my knowledge ,in this case your app does not work offline.So for that when you sync data to a server at that time maintain some flag which data is synced.And then next time just check flag status if it's synced then do not synced data otherwise do syncing.
I hope this solves your problem.
I have an android project which has a local database, when the application starts it syncs with the web service, I have a JSON file containing Countries, States and Cities of Brazil that is imported into the database as the user need this information to register the address of their customers ...
I can not get this information from the Web, because the proposal of the app is to work offline, and when you have an internet connection to send data to server.
Therefore, I was wondering if there is a way to get this data previously entered in the database and not embed them in the first inicilizaĆ§Ć£o, this works, but requires a lot of processing, it takes about 5 minutes on average (this is long ) to do the import.
Any solution?
Thank you!
My previous app has the same problem like this. I give you the solution that I did:
Before release your app, you should embed the latest database (imported by json, call db1) in asset folder, then copy it into application database folder (something like /data/your.package/databases) when initializing app, it only takes some seconds. By this way, you can query data and check user login/register normally.
Whenever device comes to internet, you just download the latest json data and import it into another database file (call db2) on background.If this progress doesn't have any errors, you can replace db1 file by db2 and it can work properly.
There is no other way to do that but you can minimize your payload using gzipinputstream, big cookie model to sync to your server, fast networking library called volley etc.,
I am missing some logic in my app. I am having json webservice which can be modiy by administrator.For the first launch of my app I am storing the data from the webservice and stores in sqlite and displays the data from sqlite using background threads.If it is second time launch then the app directly displays the sqlite data. Now the problem is if it is for the second time launch of the app how can I recognize the webservice got modified and where it is modified and how can I store the particular record?
For that I am comparing with the id's of the book in sqlite and webservice if new book enters I am able to get the new item and store it in the sqlite and display them from sqlite.But if there is any modifications in item details how can I recognize the particular tag?
Write a REST API on your web server that will send you a list of modified records. Query this API every time you start your app.
If there are modified records, This API should return you a list of the modified records which you can use to update your local sqlite database.
If not, then this API will return nothing and you can carry on happily :-)
You can create REST API's by writing server side code using a language like PHP, Ruby, Python etc
There are other options that avoid REST API's as well. See:
How to get from a MySql server to an Android app?
See here for a beginners tutorial on REST:
http://net.tutsplus.com/tutorials/other/a-beginners-introduction-to-http-and-rest/
In my application I am having database stored on the web server, I want to fetch particular values of record stored in SQL database. After getting that values want to update these values in the record stored in SQLite database of android.
Scope of question is very broad can't answer in few lines, but can give you idea. For achieving above functionality there is no any such mechanism so that android client (like tablet/mobile) directly get connected to web servers. For making this happen you need to write web services at server side which will take request from android client, process it as per request types and returns the resulted processed data. You can consume this web response at client side and do operations like saving it in Sqlite database. Similarly you can sync local sqlite database with server via web services only. You can easily consume Restful web services using Retrofit or Volley.
I am working on updating the database on a Mobile device which is using SQLITE db, which should get updated as server updates it's database i.e wamp server.
Can anyone suggests me any ideas on how to achieve this.
I don't want to read the whole server database as it would increase the Data Usage while reading the whole database just for a single update or for multiple update.
Update is done in the product table and only the price field is updated by server side.
You can define a service in your app that periodically asks if there are updated data in your server db. On the server side you can implement a web-service that will receive a json object in which you will put the current date, the table name you want to check for updates and other info based on your purposes.
I'll explaine myself better with an example:
1) when the app starts a background service will also start. This service will query (for instance every 3 minutes) your webservice to see if there are new updates for a specified table.
2) The webservice will receive the table name you want to check and the datetime preferably in unix timestamp. For instance you want want to see if there are new records for the table "products" after 2012-08-20 22:00:00 . You can create a json object and a http request with this information within your app and pass it to the server side.
3) Your web-service will respond to you giving a json array with all the data that are being added or modified after 2012-08-20 22:00:00. Of course in the server db you have to store this information (basically each record will have a field with the datetime of first insertion / last modification)
4) You can then update your local sqlite database.
Probably this is not very efficient but it works.
Andrea