xml resources or sqlite - java

i am making an android application that will use a database. the user won't be able to edit the database, the database will be static most of the times, but i will need to update the database frequently for future releases. It will only contain 1 table but with hundreds or even thousands data.
Which one should i use so that it will be efficient and effective memory-wise ? XML or SQLite ?
Any help will be very appreciated.
P.S. I have read Raw resources versus SQLite database but i decide to make a new question rather than replying to an old question.

Go for Sqlite always , File Processing is Costlier than Sqlite. And also Sqlite will be more secure than XML. The Thing that you are trying , I had been gone these kind of issues. There I started with File but at one point of time , FILE IO was making my app very slow because of huge data processing. to Overcome that Issues I used Sqlite. As a result , My app became 10 times faster !

If you plan to work with alot of data i would recommend SQLite.
It will allow you to update or alter the database when your app is released without erasing any current information from the user's phone they have in the app.(Very beneficial)
It will also be good for querying with a cursor and pulling information fast.
I would recommend this!

Related

Way to store images, text notes and audio files in offline database. Android, Java

I would like to create an app where I could save text, image and audio notes to an offline database(without internet connection) and then show them in a list-like layout. Wouldnt like to save the files to internal storage directly.
Its my first time creating mobile app so I need help in choosing the right database for such use case. Any suggestions?
I think you may be confusing some terms.
While you can put all sorts of media in a database. Sometimes it not the most practical solution. It sounds like you might be thinking of file storage, not a database.
Further more, the files have to live somewhere, if not on a external server/database, than they will have to reside locally on the device. Your app will not have a local database service running just so that it can store media files. This would be a lot of overhead and take up a lot of resources.
the first thing to know: the database in android is SQLite, So any other offline database it's just a layer for managing the SQLite database, and It only saves numeric and text data, but you can save any other type like image, audio, array...Ect by creating convertors to save it in the database.
E.g: You can save BitMap-Image type- by converting it to ByteArray-List of 0s and 1s-, then converting the ByteArray to String-Default text type-, then you can save it to the database, and when you want to select the value, just convert by the opposite (String -> ByteArray -> BitMap), So the trick here is to know how to convert between the types.
Now the answer:
the best offline-database is RoomDatabase, the fastest way to create and manage SQLite database, with Room you don't need to build an SQLite database from the scratch, it's going to build it for you, and has a great way to create converters.
but for you as a beginner, standard SQLite is more than enough, if you will see RoomDB more difficult.

Saving Things to local storage in java/javafx?

I don't know if this is a super noob question, but I'm currently building an app from scratch with the knowledge i've gained so far, and I'm making a "Notes" app where You can create notes, delete, edit(update), etc etc.
The question I'm having is that I know I can use a database to store data from my input, and I know i can use A Database to save, open the data, but Just incase, does Java have a LocalStorage, like JavaScript/JSON where you can save things and open them up later?
If there is LocalStorage for applications to save data, and open it up after running again, what would be some good resources to read about it and learn it so I may integrate it into my application?
If there is no localstorage, I wan't to be able to perhaps allow the user to add images when creating notes, how would I be able to do that using a database?
As far that I know of there packages that allow you to store data as you intend, but following on your next question, you could possibly store the address/file name of the image you wants to add to the database. You could then use it to retrieve the image file and display it.
If you have any questions on image implementing images in java, reference this documentation and tutorial
If you have any more questions on working with databases, reference this documentation
I hope this helps.

Where to place my android app's data

I'm currently developing an app that lets you create and save excercises and routines for the gym. I want the app to come with some example excercises and routines and also to give the user the ability to add his own.
The thing is, I know I can use "getFilesDir()" and save it in the internal memory, but if I do that, how do I put my example files also in the internal memory? I don't think I can do that without creating those files by code everytime the app runs. I've also tried putting the example excercises in "res/raw" but then the ones the user adds go to a different place and I don`t know if that's good practice, apart from just how annoying it is having to read them from different places.
Where would be the best place to put those excercises and routines files?
Thank you very much!
The best practice is to store data inside "Sqlite Database".
"Sqlite Database" is the internal database that android provides to store data locally and is easy to use.
It's queries are easy to implement. It is more easy to work on, if you have worked on any database before. Just create a "Database Helper" class and initiate inside the activity where you plan to store data.
Many big applications like "whatsapp", use this database to store data on user's device.
The plus point of using "Sqlite" is that, you can iterate through each and every data easily.
It is quick, easy to work and is also a good programming practice. It is also secure.
While using a sqlite database for managing your app data is the traditional
approach, there are also alternatives to it. Realm is such an alternative. You can check the comparison with sqlite and see if it meets your need.
https://realm.io/
In Android development, you can store locally and as well as remotely. This link will walk you through all possible ways to store data.
As per your requirement, I would recommend you got for SQLite Database provided especially for android as it is light weight. Sqlite queries are straightforward and easy to use with some APIs comes with the package. you can start with this link with Sqlite.
I suggest using Firebase to store your data. Not only it is online and realtime, it can also work in offline mode and sync later. Because you're developing a gym app, why not give it an online or offline capability? I think users prefer it that way. You can check it at firebase.google.com

What's the best practice when populating a sqlite database with default data?

I'm making an app that will be using few hundred database posts from a sqlite database. I will not be adding new data during the lifetime of the app (unless I update the whole app).
I might end up using a static xml for the data, but I need to flag posts, so I guess a sqlite db would do the job best. I know how to implement it and I've released apps using sqlite before...
But my question is. How to I best populate the sqlite db the first time the app runs? Should I just bring in a file that I use as a resource and then copy to the apps space? What's the best/easiest practice?
The simplest solution is to use SQLiteAssetHelper. You basically drop your SQLite database into your project's assets/ directory, and use SQLiteAssetHelper in lieu of SQLiteOpenHelper. In addition to the sample code up on Jeff Gilfelt's GitHub repo for the library, I have a sample app demonstrating it as well.

SQLite on Google App Engine

Is it possible to use SQLite as a relational database from Google App Engine? (Java) I need read/write access to it from the app itself.
Also, I am using Quercus for PHP, and if what I am asking for is possible, I can handle storing the database myself.
No, it is not possible. This would require write access to the filesystem, which App Engine does not allow.
SQL database support (MySQL like) is planned, but no release data has been given. For now, use the datastore.
I know it's a super old question and nothing concerning read-only properties of App Engine has changed since then... But actually you can use sqlite on Google App Engine. There is a writable /tmp directory (https://cloud.google.com/appengine/docs/standard/java-gen2/using-temp-files). If your app on startup first copies the db.sqlite3 file to /tmp/db.sqlite3 and references this path as database path, it will work.
The following problems are connected with this approach:
This directory is "in-memory". So if you want to use really large sqlite file, you may face problems with RAM.
Each node of the app gets its own copy of the database. If you save something on one node, these changes will not be seen by other nodes. And the new data will be lost if the app scales to 0.

Categories

Resources