Search code examples
androidexitlaunch

How do I know when an Android app is launched and destroyed?


I need to run some code when an App is launched and when it completely exits (is destroyed). I am using onCreate and onDestroy but unfortunately screen orientation changes destroys and recreates the activity.


Solution

  • Take a look at Android Application http://developer.android.com/reference/android/app/Application.html

    You can know when Application created (Application.onCreated)

    BUT you can't know when Application destroyed. Application.onTerminate() is only for use in emulated process environments.