I am currently developing a simple info app on various university campuses. I want the app to operate predominantly in an offline state thus I want to store all my information locally. The data within the app will not be subject to any change thus I was wondering what the best (practice) method was to store such data? Basically should I be storing the info in a SQLite db, java file or xml?
The answer depends on your requirements, but because of the built-in integration with SQLite, the easiest will probably be to just use SQLite, plus you get the benefits of a relational database. You can refer to the Notepad tutorial for a start.
It depends on the data you have. If it is largely text I would store it in an android string resource file. If it is somehow structured and has IDs and relations store it in a database.
We had a University project requiring a local database on an android phone. What whe did was to use SQLite to write on a database stored on the memory stick. (We couldn't find the right permissions to write directly on the file system)
Check the API website for the android.database.sqlite package first.
And here for a nice tutorial :
http://www.devx.com/wireless/Article/40842
Related
I am working on my capstone and I need to create two programs using two different languages that use a single local database. I am making a chore manager that will be a windows program and an android app. I figure out how to use sqlite for the windows app, but I cannot wrap my head around using an existing database with android studio. I need the app to be able to read existing data and display it and then based on some conditions edit the data.
If I add the database as an asset will the data a user changes using the app be usable by another windows program?
Here's my opinion: "Don't use SQLite for this." Use a regular shared database that you can (securely ...) access from both environments.
SQLite databases are files, accessed through the file-system. They are most commonly used where the data won't be shared, because, like any "shared file" database of aeons past, they are always subject to corruption if someone (or the operating system, or the network ...) does anything wrong. Whereas a conventional client/server database doesn't have these problems because it controls the data while it talks to you.
SQLite is a marvelous tool for storing structured information on a device. I've deployed many dozens of "boutique" websites which store their page-information that way. But, I think, it's not the right tool for this job.
I have an Android app I wrote that uses a sqllite database,(the app is used for the reservation) now I want to write the same app for iPhone and I want to use the same database I used in Android app. My question is can I use the same database in IOS.
If yes, then how can be used and where I place the sqllite database (I mean what folder)? and the users must be online to see the update in the database ?
Can I use an sqlite database created for android in IOS?
Yes, an SQLite database is a a file (or potentially 3 files if using Write-Ahead logging). It's simply a matter of copying the file(s).
Typically (i.e. if not specifying otherwise) an SQLite database is stored in data/data/your_package/database/the_database_name
where your_package is as per the App and the_database_name is the file name (may or may not have an extension).
Note if the database uses Write-ahead logging then 2 other files may exist, these being the_database_name-wal and the_database_name-shm. If they exist and are not empty, they need to also be copied.
However,
and the users must be online to see the update in the database ?
Is a completely different matter though. SQLite is not suited to a client/server situation, as you would have to write all the code to provide this functionality. See Appropriate Uses For SQLite.
Firebase may be an option if you don't mind Google's policies reqgarding information privacy. Otherwise you are likely then looking at something like MySQL/MariaDB.
I see a sqllite database in another application, why can't I just just drag and drop from that application to mine in the eclipse environment? that way I can use data already in that database?
Android doesn't do too well with using an sqlite database file directly. Generally the way to go around it is to package an sqlite database as a resource and on first create of the app to load that resource and then connect to it and then copy all the data out of it. The downside of this is you are essentially doubling all your data.
If you are the publisher of the other app then you can list the database as a shared database to share between your apps.
Share SQLite database between 2 android apps?
Noone has written an Eclipse plugin that does that. You can write one if you feel it is both useful and worth your time.
I'm creating my first android app that will make use of SQlite. I have zero experience with databases, except for creating a mysql database to use with wordpress...
Edit: After doing some research about rest, I'm still confused about how rest, sqlite, and android dev fit together. My goal is to access a rest-based web service through a url and access certain datasets, then store them in my SQlite database. Then I want to access the contents of the database through my java program, and use them accordingly.
The datasets can be downloaded individually in CSV format, but because I will be using so many of them, I don't want to go through every line individually and store them in the database. I'm hoping there's a more efficient way to store these datasets in the database.
My main questions are:
How can I copy the XML contents of a webpage from a url into my sqlite database? Can I do this with my java program, through the sqlite database, or a java library?
Do I only need to copy the contents of the webpages from the url into the sqlite database one time? If so, what can I do if any information is changed in the datasets?
You first need a schema for your sqllite DB. That schema should map to the objects behind the web service. For e.g, you need a Person table in your DB if there is a Person entity on the web. It depends on what all you want to capture.
When you are done designing the schema, you should start writing the code that help you create & manage DB on android. This is done with the help of SQLiteOpenHelper class:
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
If you need to keep the DB synce'd with the data on the cloud (web services), you should implement sync. Android provides a very efficient sync framework.
Also, do watch this video from Android engineers explaining the best practices: http://www.youtube.com/watch?v=xHXn3Kg2IQE
Note, to actually fetch the data from the web service you would use UrlConnection API:
http://developer.android.com/reference/java/net/URLConnection.html
This sample probably captures most of it.
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
In terms of reading CSV files, there are some good resources here:
Can you recommend a Java library for reading (and possibly writing) CSV files?
Once you have read each CSV line into an object, then you can turn around and persist it to the database. I'm the author of ORMLite so I'll talk about using it. I don't believe there is a hibernate port for Android.
There are a number of Android examples to help you to get up to speed with ORMLite. Also some good tutorials. If you want to write a number of rows at once then I'd recommend using the batch tasks ORMLite feature. For information, see the discussion about creating lists of objects on the mailing list.
I can answer your first question about " I'm not sure how to add them efficiently"?
yes, SQlite is very powerful and intelligent, you can add thousand of records in one transaction, just like traditional database, It significantly improve performance.
about second question, as my understanding, because CVS file is very simple, so you can download and analyze it by yourself.
I am developing an android program for my university. I am confused about which database to use.
What I want is that when the user is connected to the internet the program will check for any updates in the backend database. If there is any, the program will sync it with Android device.
Let's assume that after while the user opens the program in place with no internet, the program will work just fine because the file is already in his mobile.
I chose Access and created .xml file and by the help of this site: XML resources in android. I learnt how to read it.
Actually this program is my senior project. I dont want the judges to ask me why didn't I use MySQL or SQLite.
Which database system should I use? Is Access the right database system to choose?
I want to do a program that looks just like Univ of Kent program.
Parsing XML could take time, also in XML you have no choice but to load the whole file.
SQLite is fast, simple to use and very dynamic.
Android offers a very simple SQLite API. Androoid SQLite API
If you are interested in reading more about all the data storage types in Android visit this link
It depends upon your requirement. lets say you want to build something which handles and stores the data on your device locally then SQLite is a good option (you can use firebase as well).if you want to do some sort of calculation on you data on a remote server then firebase is a best choice .
by using firebase you can store your data generated by your users and then if you want you can carry out some analytics as well.
i would prefer Firebase .