How apps work
Components & Intents
Why Android apps have no main(), and the four ways in.
8 pages88 min8 interactive11800 words
- 01The four componentsAn Android app has no main(). It has four kinds of entry point that the system can start on its own — and that fact explains most of the platform's design.beginner11 mininteractive
- 02Intents and filtersAn Intent is either a named component or a question about capabilities. The difference between those two forms is the difference between a phone call and a noticeboard.beginner11 mininteractive
- 03Activities, tasks and the back stackA task is a stack of activities the user thinks of as one thing. Launch modes and flags are the rules for putting activities into tasks — and every one of them is a trade-off about Back.intermediate11 mininteractive
- 04The Activity lifecycleSeven callbacks, two ways to die, and one Bundle. The Activity lifecycle is a contract about what the system may do to your screen while you are not looking.intermediate11 mininteractive
- 05ServicesA Service is a lifecycle component with no screen. It is not a thread, and since Android 8 it is not a way to run forever in the background either.intermediate11 mininteractive
- 06BroadcastsA BroadcastReceiver gets one callback and no more. That constraint is the point — and the reason Android spent a decade restricting who may receive what.intermediate11 mininteractive
- 07Content providersA provider puts your data behind a URI, with permissions enforced by the system rather than by your code. It is the oldest IPC surface in Android and still the one with the strongest access control.intermediate11 mininteractive
- 08Context and ApplicationContext is the handle to everything the system provides — and the most over-used type in Android. Knowing which Context you hold is how you stop leaking activities.intermediate11 mininteractive
Test yourself
Test yourself: Components & Intents
Order these steps of starting an activity in another app that is not running.
Drag, or use the arrows to reorder.
- 1PackageManager resolves the intent
- 2Zygote forks a new process
- 3Application.onCreate runs in the new process
- 4ActivityTaskManager checks export and permission
- 5The Activity's onCreate runs