03. Activities and Layout

App Manifest

Declares several app components:

Activities:

Fragments:

Services:

Content providers:

Broadcast receivers:

Activity

Activity stack:

Lifecycle

     ┌──────────────► onCreate
     │                   │
     │                   │
     │                   ▼
     │                onStart ◄──────────onRestart
     │                   │                     ▲
     │                   │                     │
     │                   ▼                     │
     │                onResume ◄───────┐       │
     │                   │             │       │
     │                   ▼             │       │
     │            ┌────────────────┐   │       │
   System         │   Activity     │   │       │
kills process     │    running     │   │       │
     ▲            └──────┬─────────┘   │       │
     │                   │             │       │
     │           Different activity    │       │
     │           enters foreground     │       │
     │                   │             │       │
     │                   │             │       │
     │                   ▼      user returns   │
     │                onPause──────────┘       │
     │                   |      to activity    │
     │             Activity no                 │
     │            longer visible               │
     │                   │                     │
     │  low memory       ▼    user navigates   │
     └─────────────── onStop───────────────────┘
                         │      to activity
                         │
                 Finished/destroyed
                         │
                         ▼
                      onDestroy

Primary states:

Lifetimes:

Programmatically stopping an activity:

Architecture

Previously, the recommended architecture was a multiple activity architecture.

However, after the Navigation component Jetpack library was introduced in 2018, Google started to recommend a single activity-multiple fragment architecture.

This:

Architectural principles:

Views, View Groups and Layouts

XML

Tasks:

Misc: