Android: Flush sqlite database when app killed Android: Flush sqlite database when app killed sqlite sqlite

Android: Flush sqlite database when app killed


There probably isn't a totally foolproof way of doing this. You could clear the data in onDestroy() of your activity, though it might not get called if someone uses something like a task killer (pretty sure about this).A better option would be to clear the data the next time you start the app.


You should take a look at this method of subclassing Application and performing your table dropping/creating there rather than in onStop and onPause.


I think you should use the in-memory flag by passing null as your db name. That means the db won't be stored on sd card at all so no need to clear it before the app dies.