How Android Handles Multitasking: Inside the System That Keeps Apps Running Smoothly

Ever wondered why your Android phone can juggle multiple apps at once, but sometimes kills one you were just using?
That’s Android’s multitasking system at work a complex balancing act between performance, memory limits, and user experience.

In this article, we’ll break down how Android decides which apps to keep alive, which to pause, and which to shut down.


1. What Multitasking Means on Android

Unlike desktop operating systems where apps run fully in parallel, Android uses a priority-based process model.

Apps can stay in memory even if you’re not using them.

Processes are ranked by importance to the user not just CPU usage.

If the system needs memory, it kills the least important processes first.


2. Process Importance Levels

Android assigns every running process an oom_score_adj value a number that tells the system how important that process is. Lower values mean higher priority.

State Typical Importance Examples

Top / Foreground Highest App currently in use, game you’re playing
Visible / Perceptible High Music player with UI partly visible, video PiP
Foreground Service (FGS) Medium-High Music streaming in background with ongoing notification
Service Medium Chat app sync service
Cached Low Recently used apps kept for quick reopening
Empty Lowest No active components, just cached in memory

Fun fact: Android doesn’t kill foreground apps unless there’s a critical memory shortage — those disappear only in extreme cases.


3. The Role of ActivityManagerService (AMS)

The ActivityManagerService is the brain of multitasking:

Tracks all running apps and services.

Maintains a Least Recently Used (LRU) list of processes.

Updates process priorities based on what the user is doing.


It works closely with:

ActivityTaskManagerService – Handles tasks, activities, and the “Recents” screen.

ProcessList – Assigns oom_score_adj values for LMKD to read.



4. Memory Pressure and LMKD

When your phone’s RAM starts running low, LMKD (Low Memory Killer Daemon) steps in:

1. Monitors memory pressure using psi (pressure stall information) from the kernel.


2. Picks candidate processes to kill, starting from Empty → Cached → Services.


3. Kills them to free memory for higher-priority tasks.



If even LMKD can’t help, the Kernel OOM Killer takes over  a last-resort action to prevent a crash.



5. The Multitasking Flow

Here’s what happens when you switch apps:

1. You open a new app – Android moves it to the Foreground state.


2. Your old app – Becomes Visible or Cached.


3. If memory is fine – Both stay in RAM, allowing quick switching.


4. If memory runs low – LMKD kills the least important one to make space.




6. Why Apps Sometimes Restart

If you switch back to an app and it reloads, it’s because:

It was in a low-priority state.

Memory pressure forced the system to kill it.

The app wasn’t designed to restore state quickly.

Well-optimized apps handle this gracefully by saving their UI state before being killed.


In Summary

Android multitasking isn’t just “running apps in the background” it’s a smart prioritization system that:

Keeps your most-used apps alive.

Balances performance with battery life.

Automatically frees memory when needed.

So the next time an app restarts, it’s not Android being “bad” it’s Android making sure your phone doesn’t slow down or crash.

Pro Tip for Developers: Use foreground services and proper state-saving to keep your apps alive longer without abusing resources.

Previous Post Next Post