Skip to content Skip to sidebar Skip to footer

Write Listener When Application Close

I want to write code when application close. I want to write listener for application. I have created Application class but does not find any appropriate method as like onCreated a

Solution 1:

Looking at the documentation :

http://developer.android.com/reference/android/app/Application.html

It seems the Application class has no capabilities to do that. (dont get confuse with onTerminate).

The problem is, why dont you write the code you want to run in onDestroy of your Activity?

What is your case, so destroying the Activity does not mean closing the Application?

You might consider to read this :

When to use and not to use the android Application class?

Solution 2:

The short answer is ... there aren't!

The concept of "application close" is very diffuse: An application is a set of activities, services, etc... and a lot of things may keep the application alive.

You can't even guess when (or if) an activity onStop() and onDestroy() will be called.

Even calling activity.finish() doesn't mean any of those methods would be called instantly. Take a look at http://developer.android.com/training/basics/activity-lifecycle/stopping.html .

But there's sure a better place to do those things you have to do. What is it?

Post a Comment for "Write Listener When Application Close"