I have 2 users in my app.
1) Normal user
2) Admin
The admin can perform certain changes in the app which update my SQL table stored. Once this update is done how do I make it affect the users who aren't admins?
I'm guessing this will have something to do with a server but how?
EDIT:
Its an app that holds data of what classes are going on in different classrooms in different buildings. So I'm storing all that data in a table. so now if the admin wants to change something I make that changes in the table accordingly. But this change will happen locally on his device. How do I make it appear for all other devices?
In that case, you have to make a web server and migrate the database to that server, and all the users can access the database from there. And to reflect updates to every user, u can implement 2 methods:
The users will poll the server at regular intervals to check if there is any change in the database
u can use GCM, i.e. Google Cloud Messaging to directly send notifications to all users as soon as the database is updated.
While the first method is easy to implement, it could eat up bandwidth of the user as regular checks consume more data.
The second method is lengthy to implement, but it saves up a lot of bandwidth.Also, GCM works only on android devices, so it kind of redeces the scalability of the pp to only the android platform.
Related
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.
My current android app is azure mobile app where a user can book any service.I need to show the status of his order like booked,pending completed in a fragment.I am right now doing it by calling api but everytime fragments gets created it calls api even if no data is changed.What is the possible and efficient solution of doing this.
For your scenario, the orders data are stored in your server-side database. Though you could store the retrieved order data into the local storage (e.g. SQLite,etc) on your mobile client, in order to retrieve the latest order status, you must explicitly call your mobile app backend for retrieving the latest order info and update your local order status. At this point, you could try to decrease the response data size returned by your backend via specifying minimum fields in your request. Details you could follow the .select() field selection clause.
Moreover, you could also follow Khemraj's suggestion about the notification approach, but the push notification may needs user interaction.
I have an SQLite database on Android and a MySQL database on a server. I want to synchronize these databases when a user edits data on their phone or edits data on a website.
I know how to update the MySQL database on the server when a user makes changes on their phone but I don't know how to update the Android database when a user makes changes on the website.
I have read into push notification and believe this to be a good path to follow but I have a few questions about it:
When a user updates data through a website it will send a push notification to that user's phone saying changes have been made. Can this push notification trigger to update the Android's database with the new changes made on the Server database?
What if a user turns off push notifications? Will I still be able to trigger for their Android database to be updated?
I have also read up on SQLite and MySQL database synchronization and found this post SQLite and MySQL sync but did not find the post helpful for my situation.
Are push notifications a good way to go or should I be using a different approach?
In a nutshell - I want a way for the Android device to detect changes on the MySQL database and update its SQLite database without the user initiating the synchronization.
I'm afraid I've not used push notifications. But a solution might be: You could create an early method call to an Asynchronous polling event from the launcher onCreate() that looks up the server to see if any changes have been registered (though an API of some sort) in the MySQL, and then update the SQLite that way? Since it's the first thing that happens on launch, technically the user isn't initiating it. Granted this won't update during use of the app, unless you repeat poll at regular intervals?
Token based pagination approach.
Assumptions: or calls you need to take
One of the databases will the source of truth, in case of differences in the two, which data is true, and which will be overwritten? - assuming remote database is source of truth
What's the frequency of data changes? - assuming its not realtime critical
How much stale data are we OK with dealing on the app. - assuming we're OK with a few minutes of difference
How to ensure data is consistent
Find a method to associate a token, which can be used to identify till which record is the data in sync. This is important no matter how assured you are of web requests, they will fail. So the best method is to send the last token that have stored, and the web endpoint will return data from that token to the latest value.
If the volume of data is too much here, sending chunks > sending all of it. Chunks work the same way, based on tokens.
These tokens can be simple PK auto increment column as well.
How to deal with time difference, stale data
If your application demands some data to be near realtime, better to categorize data based on a fiew screens, and whenever the user comes to the said screen, send a request in background to fetch related data columns only. Will ensure the data stays in sync w.r.t to the important columns. This is a classic push/pull approach. Can also be done on the splash screen itself.
as a rule of thumb, if you need something urgent, pull.
if it can wait, wait for a push.
Push notifications are OK as far as:
they should be silent.
there'a a limit on the number of push notifications that you can send
have costs associated
what's the fail - check mechanism? What if the requests fail?
We are developing an application called marketwatch.where we have to show prices of basic commodities,what we have to do is create a db of commodities and their prices and display them in our app whenever we change the value in db it should be updated in our android app.
If i understand you correctly, you want your applications database to be synchronized with your actual database.
You can do this by two ways:
Pulling: which means that every time you open the application or every period of time, maybe couple of hours or something, you request from the server the updates that happened in your database, if any
Pushing: which means that when your server has an update, it should notify the mobile app by sending a push notification to tell the client that there is an update to be fetched.
You can combine both, for example low priority updates should be retrieved by pulling, but high priority ones should be pushed to the client.
Have a look at the official training resources for Sync Adapters.
Or, if you don't have any constraints for the server part have a look at Firebase (from Google)
I have an architecture question. If you have a web app that is storing information on a DB server, theoretically, I should be able to use the middle tier logic for a mobile app. When the mobile app starts it can connect and populate a local SQLite DB or use JSON to store information within the mobile app. What if the mobile app also needs to work in off-line mode? Do you have it sync the next time it is connected? Do you have the mobile pull down and populate a complete DB or so it available in off-line? What are the best ways to architect a mobile app that has to go from on-line to off-line?
The simplest solution would be to put a "LastEdited" column into every table in your database and then pull query all the data which has updated since the last sync ( and you can perform a check on the index to detirmine if you need to update or insert into your own local cache. )
The ability to delete rows should actually be limited to a boolean "isDeleted" flag in this case to keep the sync process nice and simple.
If you have then the ability to edit or create rows from your app then you should keep a local table of changes to sync when you can go online and may have to implement some form of "merge" logic.
Several things you need to consider.
If your app is read only, you should implement a 'delta sync' logic in your local d. Keep a timestamp of last sync and get updates from your server. Of course, you need to consider the local db size in getting too large.
If you app is read/write, when working offline, you need to consider the two way sync especially when same record can be updated in different devices/users.