Hello
I'm working on an android program that uses a database. My database is going include about 300 to 400 records.
My question is what is be best way to work with the database.
Should I create the database at run time via code and insert the records "manually" every time the program starts, or should I use an external database, that's located in the /assetes folder of the program?
If the second option is the way to go, could someone please give me an advice on how to do that, because I can't find any toturial that covers this subject.
Thank you!
There's another option, which is to initialize the database the first time the program is launched. See the SQLiteOpenHelper class, and especially the onCreate method in that class.
Here is a tutorial for the 2nd option you mentioned.
Put your db in the asset folder and if DB does not exist in /data/data/YOUR_PACKAGE/databases/, it will copy the database over.
Related
I searched for along time for how can I use a pre made Excel table, as a reading database in Xamarin.Android.
Of course I can't use it directly, so I tried many different ways. For example, convert to Json, upload to Firebase, and later download it, while the program runs, and fill the sqlite. This way is not effective aadn most of the time doesn't work.
Is there any chance, that someone could please explain or even give a tutorial on how to create sqlite database and work with it directly? If there any other worse or better ways to do it, please tell me.
Thank You!
If you want use sqlite DataBase for Xamarin.Android, you could use sqlite-net-pcl.
Install from NuGet: sqlite-net-pcl
You could cgeck the MS docs from the link below for reference. https://learn.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm
I have made my database using greendao and Have been testing it on the emulator so far. It was working so perfectly. And there was no memory leak and any error whatsoever .
But now I am stuck to just one single point. and that is how do I use this
pre-populated database in the application on the real device. How can I push my database into real device?
Some one suggest me to put my database file in the assets folder and later on Application start just copy it into device.
The suggestion was good, but it is not helping me as there comes the error when I run my application for the first time , but after that it goes forward But then greendao is unable to get the database it find.
The error I got at first run is as under.
can not open database
Buton second run it goes forward and there in next activity I am getting data in list using greendao , but it is not finding that database.
Please tell me :
1) How can I push my pre papulated database into the device to be use by greendao methods.
2) What is a way that is supported in all devices.
Please share me the code. Its been a long I am trying to get over this. But nothing is helping me out.
I made a simple dictionary demo for Android, which manipulates prebuilt database in assets folder with GreenDAO 3.x.
All you have to do is extended the DevOpenHelper class that GreenDAO generates.
Here is the project link: Sawloih.
Hello everyone first of all.
I am making an application for android, which I need to have a database for information.
The database management computer mailbox.
What I need is to take that database and included in the application for android'S SELECT generally.
I've been testing it on this website, but I can not get it to work. I do not think either the DB copy to memory, and then to perform the query, she says she can not find the table.
I have been debugged and saw that even the open works, but something strange happens ...
If you have some method or way of doing this, I would really appreciate it.
Thanks for everything.
Check out these resources
This tutorial by Lars Vogel
This reference article from Android website
Puit it in your assets directory in your apk, and on first use copy to "/data/data/YOUR_PACKAGE/databases/" directory. Here is SO discussion on this topic. database in assets folder
I know a simple way that can back up database. Its directly have a copy of the .db file. But the issue is when you have to update the database tables with new columns, then the backups are of no use as it is with the old design.
The work around is to have the data parsed and stored into a file. But I am not sure how easy and safe is this.
Please let me know what you feel about this subject and also let me know if you have a better idea is mind. A sample code would be handy. Thank you for your advice and time. Thank you.
You bring an interesting point up - I haven't personally thought of that before.
You can always store the "version" of your database in the database file itself (perhaps in the file name). Then, when you open the database, you can retrieve its version and have the SQLiteDatabaseHelper run its onUpgrade() method to add any new columns.
Okay, so I am still learning to do some coding here, and I seem to have gotten stuck.
I want to have a select number of documents added to a package for the Android OS
but I don't know how to store said documents. Do I add them all under res/raw, or make an SQLite database and call from there?
More importantly, I need to be able to call those documents when a search criteria is added.
I was on the Android reference site, and they add write functions for the SQLite db, which I would prefer not having as an option.
What kind of database should I implement here?
I would prefer a link to an example, but anything would help at this point.
Try reading this.
Notepad example
or make an SQLlite database and call from there?
No you don't create a SQLlite database it will be created for you after your App start the database call.
See this SQLiteOpenHelper
And SQLiteDatabase