检测时,应用程序被关闭应用程序

2023-09-12 23:45:19 作者:被猪拱的小白菜

我想知道当应用程序被关闭,因为我需要删除一个数据库,当用户关闭应用程序,只是在那一刻,当用户关闭该应用程序是合适的时机删除SQLite数据库,我怎么能检测呢?

I want to know when the app is closed, because i need to erase a Database when the user shutdown the app, just in the moment when the user close the app is the right moment to erase the SQLite Database, how can i detect this?

推荐答案

假如你不这样做完成()您的主要活动,清除您的数据库中的的onDestroy()方法可能是最接近你想要完成的任务的。正如已经指出的评论,指的http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle.

Supposing you don't finish() your main activity, clearing your database inside the onDestroy() method of that activity might be the closest of what you want to accomplish. As has been pointed in the comments, refer to http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle.