Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite database lifecycle? It is deleted when the app is closed?

Tags:

android

sqlite

I'm following a simple tutorial that creates a class which 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?

like image 418
NullPointerException Avatar asked Feb 02 '12 12:02

NullPointerException


3 Answers

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.

like image 144
Thomas Clayson Avatar answered Nov 15 '22 01:11

Thomas Clayson


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.

like image 44
Hugo Fernandes Avatar answered Nov 15 '22 01:11

Hugo Fernandes


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.

like image 30
Lalit Poptani Avatar answered Nov 15 '22 01:11

Lalit Poptani