Detect when application is closed

android, android-activity, detect

Solution

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.

Problem

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?

Original source