How recive data from SQL Server to Android Application, in autonomous manner? - android

I have created a web service which, querying a SQL Server, retrives several tables.
I'm consuming this web service using KSoap2 package in Android application, and I want maintain alligned the tables on SQL Server and tables on Android Application.
Many of the tables in SQL Server remain the same over time, but some others change frequently. I need an automatic mechanism for update the tables on Android Application, on the initiative of Server.
I think I need a socket on Android application, for listening a signal transmitted from SQL Server, the meaning of which is "the data in some tables are changed". So, then, I can use the web service call for retrieves new data.
Is this possible? anyone has suggestions?

The answer for you question is a Android Service class. It can sit behind the program and listen to changes going on your SQL server and update it in SQLite database (or whatever you have)

Related

how to make a synchronous android application with sqlite

Unfortunately, I didn't find a better title for the question
i want to make application like a simple hotel reservation and i will make the database online if i add client to the hotel database via android application i want it pending and When I'm online i want the command execute but in the same time when i'm offline i want to see the that the command pending , it's like whatsapp when you send message while you are offline the message not send and you see it pending and when the internet available The message is sent automatically
so how i can do that ?
SQLite may well not be ideal solution. The reason being that SQLite is an embedded database not really designed for the client server model (the hotel database would, according to your decsription, be on a server). Appropriate Uses For SQLite
Perhaps Firebase Realtime Database
could be more appropriate.
However, if you wanted to use SQLite to just handle the requests from the device SQLite could perhaps be used for that aspect. For the requests to be sent automatically you'd need to look at perhaps running a service. Services overview. You would probably want to incorporate Notifications
If using SQLite then the first step, database wise would be to design the database, the table(s) and the columns within the tables. However, to do so requires that the system itself is designed. System design, would depend upon what can actually be done.

Syncing SQLite database with remote mysql data in android

How to synchronise SQLite database and remote MySQL data in android?
To make it clear, I want to know how syncing between sqlite data and remote mysql works .. i.e., when the remote mySQL database is updated, SQLite data should also be updated without any button press or scroll down? How can I implement that using Android Studio and Wamp server ?
Thanks in advance!
I guess you can use broadcast receiver inside a service of your android application. If not you can write a service and inside the service you can use a timer to send http request to the server and keep syncing. To get a knowledege about syncing a SQlite database with remote mysql database refer to this tutorial and if you need it to happen without a button press then implement the code in the following tutorial inside a service and remember to use a timer.
TUTORIAL LINK
I don't know any way to make a mirror of your mysql database on your android's sqlite database. There are two ways I can think off when it comes to synchronizing data on your phone. The first one is by using a syncadapter. But this will only pull the data from the server and so you won't have your synchronization as soon as an update is done.
The second one is by using push notifications. With FCM, firebase cloud messaging, or GCM, google cloud messaging, you can tell your server to send a message to every phone that is connected to it. Your phone can then handle the message and synchronize itself with your database. Obvisouly in either solutions you won't have a direct access to your database as it brings huge security problems so you'll need to pass by a web server with an API to connect your application to your database.
Here are some useful links about FCM, Syncadapters, etc

Android update multiple local SQLIte tables, from remote MySQL server(PHP), what should I do?

I need this for a custom app, built for a specific company, so it will not be on Google Play.
I have an app, that uses about 15 SQLite tables. It needs to be able to work offline and online, so I have to use SQLite to keep information for the offline part.
The main idea is that when user on Android touches a button, an update process is starting.
The logic of the update is:
For each local table I have a AsyncTask class dealing with the update process described bellow
Every local SQLite table have an "_id" field (autoincrement) AND "idremote" field to be filled with MySQL id of the record (plus the rest of the fields)
Each time the update starts, the app prepares a string containing all "idremote" id's from the local table and sends it to the server
On the server side, a PHP file receives the string of ID's and checks in the MySQL table, to see if there are new ID's that are not in the received String of ids (each AsyncTask has it's own php file on the server)
If the PHP finds in MySQL table new ids, then it sends the new records using JSON back to Android
I process the resulting JSON in onPostExecute of the AsyncTask and insert the new records in the SQLite table
So I have 15 AsyncTask classes that all perform the same operations as above, each of them dealing with a specific table.
I also do the update of the remote tables sending the new records to MySQL through the same mechanism
My problem is that I want to be able to see/know when the update is done/finished so I can notify the user of that fact, but since we are talking about multiple AsyncTasks ... that run simultaneously... I have no idea how to implement this. How to find out when all the AsyncTasks are done?
Or is there a better way to do this task? The update of the local/remote tables?
Thank you
The best way to do this would be using a SyncAdapter which is designed to handle syncing changes to a remote server in the background.
You can find more information here: http://developer.android.com/training/sync-adapters/index.html
You should ignore the section "Creating a Stub Content Provider" and create a content provider to access your existing SQLite database.

Android | Update sqlite from mysql or update app with newer sqlite db?

Still newish to Android.
I need some advise, Should I
1. have a local sqlite DB, and have the app check for new records uptop in a mysql DB
OR
2. Publish my app with a full sqlite DB. When ever I insert new records to the full sql lite DB then publish updates?
I've been scouring the internet for some guidance. Since I am still newer to Android I wonder the difficulty in making #1 work (since I'll have to gen the php code as well).
My suggestion is:
If it's only 200 records now, it doesn't really matter if you preload it or get it from a web service (getting the data will be very quick). Usually preloaded database is better when there is a lot of data and you don't want the user to wait to long before using your App.
On the other hand if there is a lot of data, it will increase the apk size.
Create a web service method for updating the data from the server.
Create a web service method which indicate the client to delete some rows (I dont know what your application does, but usually it's needed)
What do you mean by 'uptop'? Assuming you mean 'online via an API'.
depending on the nature of your data (is is mission critical? what's the risks if it is stale? etc), it's good practice to pack static data with the app that can be referenced by the app much sooner than the updated data...the updated data is a task you run to update that stale data, and perhaps continue to run periodically to keep it updated.
It's bad practice to pack a SQLite db itself in an app, as some manufacturers do their own thing with the implementation of SQLite itself. So pack the SQL as text and create a fresh DB on the device with that.

Android notification when sql row is added

How would one go about creating a notification when a row is added to a remote SQL server?
For example, if user A inserts a row into the SQL table via a PHP script is there a way for user B to get some sort of response from the server to know to display a notification something has been added to the database?
Any help would be greatly appreciated
Depending on the underlying database (I've only done it in mySQL and Interbase/Firebird), there's usually a mechanism available to have an update/insert trigger either update another table (which you could pull) or broadcast a message on a socket (which could then generate a notification).
That said, a good web application is build around a framework, and those frameworks usually abstract the database interaction. In short, find the spot in the php script where the row is inserted, and hook your notification code in there. It'll be much more reliable, and more instantaneous.
As far as notifying the remote application, you might want to look into GCM.

Categories

Resources