Android Architecture Pictures
satya - Friday, May 28, 2010 4:04:32 PM
Activity/Process Lifetime
Key elements are
The activity comes to life between onCreate and onDestroy. The message thread continues to run for the this life of the activity.
when the focus is taken away from your activity because of an overlapping activity you go into pause and you are partially visible. when you are fully hidden you will go into onstop and then when the process is taken out ondestory is called.
The message loop however continues to run after onpause and also after onstop and until onDestroy is finsihed.
satya - Saturday, May 29, 2010 11:17:44 AM
Android Process, Components, Threads, Clients
Key elements are
An android process can host 4 types of components a) Activity b) service c) Provider d) receiver
For internal calls all components respond on the local thread using a combination of direct calls or deffered queued calls.
For an external client component there are two paths. For external components only a service and a provider are multi threaded using a thread pool. The activity calls and importantly broadcast receiver calls are routed through the main thread and its queue.
Moreover a call to a broadcast receiver is monitored to be returned with in 10 secs. This restriction doesnt seem to exist for a provider or a service call for an external client. However it is not a free ride as the external clients main thread is waiting on these calls to come back in a synchronous manner.
satya - Saturday, May 29, 2010 11:56:24 AM
Main thread, handles, and messages
Key elements are
Messages are dropped into the main thread's queue
Main thread goes through each messages and calls the handler
The handler respond by calling client specific logic that deals with other internal or external components.
what is not shown in this diagram is that in the code one doesnt have direct access to the queue but a client gets a fresh handler first which attaches itself to the queue of the current thread. Then the client can use this handler to send messages to that queue which are targeted back to this handler.
Conceptually the picture above is right but the mechanics in code are slightly different.
Read the note on Understand Android handlers, messages, runnables, and threads to see the differences