I’m developing directly on the mobile device, and I have some questions you hopefully could help me clarify about development using a database:
-
My app is meant to use a SQLite database (readonly mode), so I’d like
to know where I should place the .sqlite file created on the pc, in
order for the app to read or even directly. -
Later, the app is supposed to download the db file from a
centralized server. So, the idea is to keep putting that file in the
same location, one the app will surely know and could check if it
exists just before trying to use it.
Thanks!
You will need to package your SQLite database as a resource (e.g., res/raw) or asset with your application. However, you won’t be able to use the packaged SQLite database directly. You will need to copy it to where Android expects your app’s database files to be located and then use it from there. The best way to do this is to use
Context.getDatabasePath(String)(passing the name of the database file) to determine the file path. That’s also where you should place a database file that your app downloads at run time.