Sqlite database lifecycle? It is deleted when the app is closed?
I’m following a simple tutorial that creates a class wich extends from SQLiteOpenHelper and creates a DB with one table and 5 rows.
OK, but I need to understand some more about android Sqlite databases. For example, what happens if the app is closed or the phone is off? Is the database deleted?
4 Solutions collect form web for “Sqlite database lifecycle? It is deleted when the app is closed?”
Of course the database isn’t deleted. I assume you’re doing it the “proper” way. In which case the database is persistent. (of course if you choose to create a database in a temporary directory or something similar then its not going to work properly).
Think of it like this. The database is basically a text file. What you’re doing to the database is modifying the contents of that text file (ok its a little bit more complicated in real life, but its a good way to think about it).
Once you’ve made a change to the database (e.g. added a row) the database file is saved onto the disk thus persisting it. If the phone is turned off or the app is quit then the database file persists and you can keep connecting to it in the future.
what happens if the app is closed or the phone is off?
Answer is No, database not deleted, your data is only deleted when you
Uninstall the Application or
Clear data from
Application->Manage Application->Application_Name from your device.
When a database is created it lives in your applications private file store and is only deleted when you explicitly delete it (using Context.deleteDatabase) or when your application is uninstalled.
The database is deleted only when your app is deleted, the user clears the data associated with it or you do it programmatically.
Therefore, your app can be killed or the phone rebooted and your database persists. That’s why database is considered to be a persistent storage.