Mick
Mick

Reputation: 7947

Application lifecycle

I have seen nice diagrams showing the lifecycle of an activity, but I can not find a diagram showing the lifecycle of an application - is there one?

In an activity onCreate is kind-of paired with onStop, I say paired in as much as you know for sure that if onStop() is called then you know for sure that the activity won't run again without calling onCreate(), you can see this at a glance from the diagram.

The particular thing I'm looking for is what method is paired with onCreate in the lifecycle of an application? is it onTerminate?

EDIT: I have something like the following:

public class myapp extends Application
{
    @Override
    public void onCreate()
    {
             special_function_startup();
    }
}

I want to have a special_function_shutdown() somewhere and I don't want special_function_startup() to be called if it is already started up. So the perfect place to put the special_function_shutdown() is in the method that "corresponds to" onCreate(), like onStop() does in an activity.

Upvotes: 0

Views: 247

Answers (2)

CommonsWare
CommonsWare

Reputation: 1007554

I can not find a diagram showing the lifecycle of an application - is there one?

Not really.

The particular thing I'm looking for is what method is paired with onCreate in the lifecycle of an application?

If by "application" you mean Application, then there is nothing paired with onCreate(). An Application is never explicitly destroyed; it lives for the entire process lifetime.

is it onTerminate?

onTerminate() is never called.

Upvotes: 1

Karan_Rana
Karan_Rana

Reputation: 2823

There are four different types of application components. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.

Here are the four types of application components: Activities Services Broadcast receivers Content providers

So the application life cycle depends upon its components life cycle instead.

Upvotes: 2

Related Questions