开发者

Android: Flush sqlite database when app killed

I'm working on an app that stores some information inside an SQLite DB.

My problem is that I'd like to clear all data from the database when the app gets killed or the pho开发者_如何学JAVAne restarted. Does anybody know I can I do this?

Thanks Marco


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜