mdeudon
mdeudon

Reputation: 1

Life cycle of an application / activity and broadcast

An Android application is usually composed of : - an main activity which is the entry point - other activites - broadcasts - services

when I start my application : - the main activity is loaded in memory - my main activity starts other activities using startActivity() - a broadcast is loaded in memory - a service is loaded in memory

The question is : When I press the back button of my cell phone what happens exactly for all the components of my application : - I guess the main activity is destroyed - what about other activites started in my application - is the broadcast still alive ?

Regards

Upvotes: 0

Views: 370

Answers (3)

sstn
sstn

Reputation: 3069

Besides what others said, Android will (usually) create a process for your application the first time your activity/service is started or broadcast receiver is called. Android will manage the activity and service according to their documented life cycle.

The process itself may remain in memory indefinitely (basically until android decides it might need the memory it is occupying) - but that's not really something you need to care about.

Upvotes: 0

Timo Ohr
Timo Ohr

Reputation: 7947

BroadcastReceivers aren't created with your application, they are created when the broadcast actually happens, which is completely separate from your application life cycle. In general, BroadcastReceivers only exist during the execution of their onReceive-Method. It just happens to be that they share a process with their corresponding application if one is already running.

With services things get a bit more complex, but if you don't use them outside of the current application and didn't explicitly put them in a different process, they will disappear too when all Activities in your application have disappeared. Not necessarily immediately, but you have to expect it.

Upvotes: 1

dave.c
dave.c

Reputation: 10918

Have a read of the application fundamentals, it covers the lifecycle of each of the application components.

Upvotes: 0

Related Questions