Android processes

Android startup sequence
1. Bootloader
Initializes hardware.
Loads the Linux kernel into memory.
Passes control to the kernel.
2. Linux Kernel
Starts low-level drivers.
Mounts the root filesystem.
Starts the
initprocess (PID 1).
3. init process (Android Init)
init process (Android Init)Reads
init.rcscripts.Starts key system services, including:
servicemanagervoldsurfaceflingerzygote
4. Zygote
Preloads system classes/resources
Preloads Android framework classes
Preloads common libraries
Forks to create:
System Server (which manages system services)
App processes when apps start
Application startup

1. User Action and intent creation
The user clicks an app icon.
The Launcher is just another app.
It builds an Intent describing which Activity should start.
It sends this intent to the Activity Manager Service (AMS) using Binder IPC.
2. Activity Manager Service (AMS)
AMS is the system component that manages:
Intents
Activity life cycles
Permissions
Tasks and back stack
When AMS receives the startActivity(intent) request, it:
Resolves the Intent
Checks permissions
Determines whether the app already has a running process
If the app does not have a process running, AMS goes to the next step.
3. Process creation via Zygote
AMS calls Zygote to ask it to clone itself to create a new process for this application via Process.start() (the new process becomes the application process).
4. Activity Thread + Dalvik VM (ART)
Inside the newly forked process:
Android runtime starts (Dalvik VM in older Android; now ART)
It launches the ActivityThread class
ActivityThread is NOT a thread. It's a manager for the app’s main thread responsible for:
Starting activities
Running the main (UI) thread
Managing the Looper (Looper.loop() starts the event loop)
5. AMS communicates with the new process**
After the process is ready, AMS sends in order:
BIND_APPLICATION: it tells the new process:
Load the app package
Initialize classes
Prepare resources
LAUNCH_ACTIVITY: it tells
ActivityThread:Call the lifecycle methods of the Activity.
6. Activity Life Cycle Begins
ActivityThread now calls:
onCreate()
onStart()
onResume()
Main components
Activityclass: unlike programming paradigms in which apps are launched with amain()method, the Android system initiates code in an Activity instance by invoking specific callback methods that correspond to specific stages of its lifecycle.
Activity lifecycle

Last updated