Android Question Database

Stefano Di Chiano

Active Member
Licensed User
Hi, I was wondering one thing.
Let's say I put a db in the application folder, so I don't create it by code but I copy and paste one I already had.
When I upload the apk on the google store and someone download the app, will the db be downloaded as well?
I don't know if I'm explaining myself well or if it's a dumb doubt, but what I mean is: do I have to create the db when the app is run the first time or I can just put one in the Files folder (or whatever the right folder for dbs is)?
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
Copy an existing Db file has a price: You have to think about overwriting an existing Db file, because in such case all user Db mutations are lost. Crate a Db file from the app can detect the existence an only add non-existing table(s) or upgrade an existing table(s) design.
 
Upvote 0

Stefano Di Chiano

Active Member
Licensed User
I don't want to copy it, I just a need an already existing and filled one when the user download the app.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I don't want to copy it, I just a need an already existing and filled one when the user download the app
You must copy the database to File.DirInternal or if you use RunTImePermissions to the external. You cannot open or read a SQLite database when it is in FIle.DirAssets
 
Upvote 0

Stefano Di Chiano

Active Member
Licensed User
You must copy the database to File.DirInternal or if you use RunTImePermissions to the external. You cannot open or read a SQLite database when it is in FIle.DirAssets
I didn't know that. How do I write the code in a way that it doesn't copy it every time the app is run?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…