I am pretty new to databases but I have an idea I'm trying to implement and I'm looking for some answers on if I'm going down the right path here.
I'm trying to create an app that displays locations in a list or on a map. The locations are going to be stored in a MySQL database hosted by Amazon Web Services. When the user opens the map portion of the app the database will be queried and the locations within the map view will be displayed. I figure the database won't be super big (around 10k locations) so I think it would be best to download the entire database and store it client-side on the users cell phone. There would have to be some kind of version check to determine if the user has the latest version of the database. Where would the version of the db be stored? Does the database or table automatically have a version number that increments automatically?
Second part of the question - is downloading the entire database (although small) a good idea? It seems like it would cut down on multiple database accesses per session and use less network traffic (anytime the user moves the map they would have to query for more locations within that area). I'm just trying to figure out if this is the best way to go about doing this since I'm brand new with databases. Thanks for any input.
Android has support for SQLite when it comes to embedded databases.
First you should check the compatibility between MySQL and SQLite SQL if you want to download the entire database.
Also, in android there is a class called SQLiteOpenHelper which has an onUpdate method that comes handy when one must update the database.
In my experience, I would recommend using a web service instead of downloading the entire database, mainly because of bandwidth and security issues.
Related
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.
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.
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.
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
I'm developing an Android app as a "proof of concept" for our company. If they like it and think it's worth investing, then we'll move on to bigger things. I'm trying to figure out the best/most practical approach for this.....the basics of the app will connect to our DB and display information regarding a specific customer. For now, let's say we will only pull data from 3-4 tables (but there could be 10+ in the future). If the app doesn't have an internet connection then it should use the local DB. What is the best approach for this? Here's what I was thinking and would like some input/suggestions if possible:
1.) app runs checks internet connection. If exists, check db version (how, through a web service?)..if server db is newer, get latest data. If no internet, use local db.
2.) app parses data and displays it.
If this is correct, then there could be no modifications to the web service that would add fields to a result without changing the app as well. Is there a way for an app to parse fields regardless of how many fields there are?
I've read and walked through the tutorial on google with databases and such (Notepad tutorial) but it seems like the column names are all hard-coded in the parsing class, which I was hoping to avoid.
Sorry if this is confusing but I know I need my app to use a local db to read data, I also know that the app must get data from the server when it can (via onCreate or a refresh button) and copy it locally....Copying it locally is the part I'm having trouble understanding I guess....is there no way of saying "go out and get this result and display it", knowing that those results could mean 5 fields the first time or 1 the next.
Any help/guidance is greatly appreciated!
You probably want to use a SQLLite DB to store your data locally, a ContentProvider to provide CRUD access to the db, and a SyncAdapter to sync with your server when possible. The Sync Adapter also writes to the DB via the ContentProvider. See the SampleSyncAdapter sample in the SDK for an example of how this works. You will be implementing your own ContentProvider, but the sample just uses Android's supplied Contacts ContentProvider.
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html