How to update an SQLlite database periodically through the internet ? - android

I am making an android application that needs to update periodically an SQLlite database of strings. Can updation be done through the internet, if yes how ?
I have a few lists in my application which are filled by the SQLlite database. The contents of the lists needs to change every day. That's why I need to update it everyday.

Yes you can update your Sql Database from the internet. See Guide to Services.
You can fire an Intent Service which does the work on a separate thread and there you can make a connection (for example HTTP GET request) and then put the parsed data in your appropriate database.
If you are using Loaders to populate your list, the list will be updated when you store new data in your database.

You may take following approach:
maintain a date variable in the shared preference or sqlite and on application launch check that if todays date is greater than date stored then you can call the rest/soap based web-services and fetch the updated record from server and update your sqlite table.In turn your list will populate the latest data...use cursorAdapter for that
OR
you can implement a GCM(google cloud messaging) service on your server,which push the updated data from sever to client every day.
OR
every time you launc an application you can hit the web service and upadte your sqlite database.
I hope solution caters to your problem

Related

Get data from/to Android app every time data changes in web service data base

This question might have been answered previously but I could not find it. Apologies for that.
In my android application I have a List with orders data.
I have my web service which can send the Orders data from the database.
I am familiar with the way where the Android app can request the web service for Orders data.
If my Orders data from the web service (database) changes every minute/seconds and I want update the List view instantaneously. Is Running an Async task every second to check with web service for new data a good way? I think this kills the battery life as the Async task runs every second.
Is there an alternative best way to do this.
Can web service constantly check its data base and send data to the android application if the data in the orders table changes.
I have heard about Firebase from Google not sure if that serves the purpose.
Could you advice me on whats the best way to get the data every minute or second from the database.
Firebase Realtime Database is what you want. It updates data in real-time.

SQLite Updating tables with read only data to App users

I am new to the android development and having certain concerns below
(i)In my app i am using SQLite database in which user should only be able to read the data (so i am running only reading the db query in app code)
db = openOrCreateDatabase("PersonDB", Context.MODE_PRIVATE, null);
db.execSQL(SELECT * FROM persons);
(ii)To display fresh data(eg news etc) to users i need to update my tables every day but i am not sure how to do that ?
PS: I know the code of how to make users to insert data by using an android app but here in this case only i want to insert the data(not by the users of app)
Can someone help me on this one?
Thanks! in advance
You can implement a SyncAdapter with periodic sync that runs each day to update the database.
https://developer.android.com/training/sync-adapters/creating-sync-adapter.html
Also you if you can integrate your backed with Google cloud messaging (or the newer FireBase cloud messaging) to notify the app to retrieve fresh data when available
https://developers.google.com/cloud-messaging/android/start
In both cases, you'll retrieve data from the server and update the db within a Service so that the updates take place even if the app is not running.
UPDATE:
In case of SyncAdapter, the data transfer code can be implemented in the onPerformSync() method. As for updating the databse, SyncAdapter plays nice with ContentProvider which makes the CRUD operations easier.
So in that method, you'll fetch the data from the network, open the database for writing and insert/update new data records. the SyncAdapter has a getContext() method that you can use for any context operations.
You can also check this application I implemented, it has a SyncAdapter and ContentProvider.
https://github.com/MinaSamy/WeatherApp/blob/master/app/src/main/java/com/bloodstone/weather/sync/WeatherSyncAdapter.java

How to observe the changes made in Remote sql database table from android

Currently am developing an android application in which i wish to intregrate the webservices and save the received datas in my sqlite database.Further if there is any changes in my remmote sql i wish to update the same thing in my sqlite too.How can i acheive this..is there any way to acheive this.I just stuck in this thing for more than 2 days.
You have many options to perform the task:
You can ping the server for updates, for example if you upon starting call some API method getItems and store the items on local database, you can after certain interval call getItems again and replace the old items with the new ones
You can use a service like GCM (Google Cloud Messaging) to archieve this so your server sends the updated items straight to your phone, but this really depends on the application you're using it on

Update sqlite database when server database get updated

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

Android updating database differentially

HI All,
I am developing an application which would need to regularlay update the database from the server. I am planning to get the database from server in json format.
But I want to update the data for those records which have been updated on the server. I do not want to download the complete database but only the differential database so that data transfer is minimum each time.
What is the best way to achieve this? Any sample code available?
Rgds,
Sapan
Simply put a *modified_date* column in the corresponding tables in the database and ensure it is updated by server(or some other mechanism such as using database provided facilities) whenever a row is updated/added. At any time you can request the records which have *modified_date* greater than the time when last query was executed. On your application you have to maintain the time when the data was last fetched.

Categories

Resources