Lifecycle in Mobile Development: what it is, stages and how it works

Author: IT Sectr Published: 2026-03-02 Reading time: 9 min

The mobile app lifecycle determines how an app behaves when launched, minimized, returned from the background, and closed. In this article, we'll cover App Lifecycle (iOS), Activity Lifecycle (Android), Fragment Lifecycle, ViewController Lifecycle and LifecycleOwner. Understanding these processes is critical for preventing memory leaks, data loss, and incorrect app behavior. More details can be found in the official Android Activity Lifecycle documentation.

Key Takeaways

  • Activity Lifecycle (Android) includes 7 methods: onCreate → onStart → onResume → onPause → onStop → onDestroy + onRestart
  • ViewController Lifecycle (iOS) is called in order: viewDidLoad → viewWillAppear → viewDidAppear → viewWillDisappear → viewDidDisappear
  • iOS App Lifecycle has 5 states: Not Running, Inactive, Active, Background, Suspended
  • Fragment Lifecycle is tied to Activity but has its own methods: onAttach, onCreateView, onViewCreated
  • LifecycleOwner (Android) allows subscribing to lifecycle events via LifecycleObserver

App Lifecycle

Before diving into the lifecycle of individual screens, it's important to understand the lifecycle of the entire application as a whole. In iOS, the app goes through five states: Not Running, Inactive (in background, not receiving events), Active (active), Background (in background, code is executing) and Suspended (in background, code is paused). These states are managed in the AppDelegate through the methods applicationDidFinishLaunching, applicationDidBecomeActive, applicationWillResignActive, applicationDidEnterBackground and applicationWillTerminate.

In Android, the equivalent is the Application Lifecycle, tracked through the Application.ActivityLifecycleCallbacks interface. However, Android focuses more on the lifecycle of an Activity — an individual app screen. This is because an Android app can consist of multiple Activities, each with its own cycle.

The modern approach in Android is to use ProcessLifecycleOwner from the lifecycle-process library. It allows tracking the state of the entire process without being tied to a specific Activity. In iOS, UISceneDelegate (since iOS 13) or AppDelegate is used for tracking app state. SceneDelegate handles multiple windows (multiwindow) on iPad. Understanding the App Lifecycle is especially important for IT Sectr when developing apps with background synchronization, streaming, and VoIP calls.

Activity Lifecycle in Android

Activity is the basic component of an Android app, representing one screen. Activity has a clearly defined lifecycle managed by the operating system in response to user actions and system events (screen rotation, incoming call, low memory).

Method Description What to Do
onCreateCalled once when the Activity is createdUI initialization, findViewById, ViewModel setup
onStartActivity becomes visibleStart animations, register BroadCastReceiver
onResumeActivity gains input focusStart camera, sensors, animations
onPauseActivity loses focus (partially visible)Save drafts, stop animations
onStopActivity is not visibleRelease resources, stop updates
onDestroyActivity is destroyedClean up all references, unsubscribe from LiveData
onRestartCalled before onStart after onStopRe-initialization

Important: onSaveInstanceState is called before onStop to save temporary state. Restoration occurs in onCreate via Bundle savedInstanceState or via SavedStateHandle in ViewModel. Without proper lifecycle handling, the app will lose all unsaved data on screen rotation.

kotlin
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        outState.putString("draft", draftText)
    }
    override fun onDestroy() {
        super.onDestroy()
        // Отписка от всех подписок
    }
}

Activity Lifecycle in Jetpack Compose

In Jetpack Compose, the Activity lifecycle remains unchanged, but Compose provides additional tools: Lifecycle-aware composition via LifecycleOwner, LifecycleEventEffect and DisposableEffect for automatic resource cleanup on destruction.

Fragment Lifecycle in Detail

Fragment in Android lives inside an Activity and has its own lifecycle, partially overlapping with Activity but adding new methods. Fragments can be added, replaced, removed without destroying the Activity, making them more flexible but also more complex.

Key Fragment Lifecycle methods: onAttach — Fragment attached to Activity (first call); onCreate — data initialization; onCreateView — View creation; onViewCreated — View created, UI can be configured; onStart — Fragment visible; onResume — Fragment in focus; onPause — Fragment loses focus; onStop — Fragment not visible; onDestroyView — View destroyed; onDestroy — Fragment destroyed; onDetach — Fragment detached from Activity.

Key difference from Activity: onCreateView and onDestroyView can be called multiple times (e.g., when switching TabLayout), while onCreate is called once. Accordingly, View initialization should be done in onViewCreated, not in onCreateView. Resources related to the View (e.g., RecyclerView adapters) should be cleaned up in onDestroyView.

ViewController Lifecycle in iOS

UIViewController is the base class for managing screens in iOS. Its lifecycle consists of a sequence of methods that UIKit calls automatically. Understanding this cycle is critical for proper UI initialization, data management, and memory handling.

Method When Called Typical Use
loadViewWhen the View Controller loads its View hierarchyCustom initialization without storyboard
viewDidLoadAfter View is loaded into memory (once)UI setup, load initial data
viewWillAppearBefore the View appears on screenUpdate data, subscribe to notifications
viewDidAppearAfter the View appears on screenStart animations, start tracking animations
viewWillDisappearBefore the View disappears from screenSave state, unsubscribe from notifications
viewDidDisappearAfter the View disappears from screenStop animations, release resources
deallocWhen the View Controller is destroyedRelease all resources

Important: viewDidLoad is called only once in the lifetime of a View Controller. To update data on every appearance, use viewWillAppear. If you subscribe to NotificationCenter in viewWillAppear, be sure to unsubscribe in viewDidDisappear to avoid memory leaks.

SwiftUI Lifecycle

SwiftUI manages the lifecycle of Views through View structs. Instead of callback methods, SwiftUI uses onAppear and onDisappear modifiers. For global app states, the App Lifecycle is used via App and Scene protocols. SwiftUI automatically manages the creation and destruction of Views based on state, simplifying development but requiring an understanding of View identity and lifetime.

swift
struct ContentView: View {
    var body: some View {
        Text("Hello")
            .onAppear {
                print("View появилась")
            }
            .onDisappear {
                print("View исчезла")
            }
    }
}

LifecycleOwner and LifecycleObserver in Android

LifecycleOwner is an interface from Android Architecture Components that marks an object having a lifecycle (Activity, Fragment). LifecycleObserver is an interface that allows an object to subscribe to LifecycleOwner events. Together they form the foundation of reactive lifecycle management in modern Android development.

Instead of explicitly calling methods in onStart/onStop, it is recommended to use DefaultLifecycleObserver (replacement for the deprecated LifecycleObserver with @OnLifecycleEvent annotations). This is the approach promoted by Google for ViewModel and other components that need to react to lifecycle events without having direct references to Activity or Fragment.

kotlin
class MyObserver : DefaultLifecycleObserver {
    override fun onStart(owner: LifecycleOwner) {
        // Подписка на обновления
    }
    override fun onStop(owner: LifecycleOwner) {
        // Отписка
    }
}

At IT Sectr, we use LifecycleOwner in all Android projects. ViewModel subscribes to the Activity's LifecycleOwner via viewModelScope and lifecycleScope, guaranteeing automatic cancellation of coroutines when the Activity is destroyed. This prevents memory leaks and makes the code cleaner and safer.

Frequently Asked Questions

What states does an Activity go through in Android?

Activity goes through six states: Created (onCreate), Started (onStart), Resumed (onResume), Paused (onPause), Stopped (onStop), Destroyed (onDestroy).

In what order are ViewController Lifecycle methods called in iOS?

Order: loadView → viewDidLoad → viewWillAppear → viewDidAppear → viewWillDisappear → viewDidDisappear. viewDidLoad is called once.

What is LifecycleOwner in Android?

LifecycleOwner is a component of Android Architecture Components that owns the lifecycle of an Activity or Fragment. It allows subscribing to events via LifecycleObserver.

What states does the App Lifecycle have in iOS?

The iOS app goes through five states: Not Running, Inactive, Active, Background, Suspended. Transitions are managed via UIApplicationDelegate.

What is Saved State on Android?

Saved State is Android's mechanism for preserving Activity/Fragment state on screen rotation or process recreation. It uses onSaveInstanceState and SavedStateHandle.

Summary

  • Activity Lifecycle in Android (onCreate → onDestroy) — the foundation of screen state management
  • iOS ViewController Lifecycle (viewDidLoad → viewDidDisappear) — the key to proper UIKit operation
  • Fragment Lifecycle is more complex than Activity due to onAttach/onDetach and onCreateView/onDestroyView
  • LifecycleOwner (Android) allows reactive subscription to events without memory leaks
  • App Lifecycle manages the state of the entire application (Active, Background, Suspended)
  • SwiftUI uses onAppear and onDisappear instead of traditional ViewController methods
  • Proper lifecycle handling prevents up to 80% of typical mobile app crashes

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project