In the last post we talked about Zygote, and how that special process launched applications. But for Zygote to launch an application is necessary to be requested. Users request to launch an application via a tap on an App icon from the home screen. The home screen as users know it is an application and the only one listening for onClick(). When this happens the launcher contact the ActivityManager. That is, request a handler through the Binder and call startActivity() method from the Activity Manager. If you remember from the Binder post, when an application wants to contact a remote method from another service, it first request a handler to the Binder, this will ask for that service to the Service Manager and pass that handler to the originator. When the Activity Manager receives the request to startActivity() it contacts Zygote to fork itself and start that new VM to run the application. It does this via startViaZygote() method which will open a connection to the Zygote socket (/dev/socket/zygote).
Now you can see how all the previous posts fall together in Android, cool eh 🙂 (images: from Embedded Android)
But the Activity Manager not only do this. It is responsible for many other tasks. This service is responsible for such an important task as broadcasting intents. You probably saw that scary pop up message saying “Application Not Responding” aka ANR. Then you should know that the Activity Manager is the responsible for this. Not only that, it also sends the intent INTENT.CATEGORY_HOME once it finish booting and reports System Ready, broadcasting the rest of the system this information. If you check the documentation of the service (http://developer.android.com/reference/android/app/ActivityManager.html), you will see the available public methods and make yourself an idea of how much this guy is doing.
This service is tremendously big, is huge and has lots of tasks to talk about. This is an the introductory post to the service but we will certainly come back to those tasks and see on code how are done. In the meanwhile you might want to talk a look to the public code, you can located in google source. That exposes the public API.