Sobes.tech
Middle

What happens to UIViewController when the app is minimized?

sobes.tech AI

Answer from AI

When minimizing an application, the UIViewController that is currently visible to the user goes through the following lifecycle stages:

  1. viewWillDisappear: This method is called before the view controller's view is about to be removed from the view hierarchy. Here, you can save UI state or cancel operations.
  2. viewDidDisappear: This method is called after the view controller's view has been removed from the view hierarchy.
  3. applicationWillResignActive: This method is called in the AppDelegate before the app transitions from active to inactive state (e.g., when minimizing or receiving a call).
  4. applicationDidEnterBackground: This method is called in the AppDelegate after the app has entered the background. In this state, the app has limited time to perform tasks and may be suspended or terminated by the system. The UIViewController remains in memory, but its view is not visible.

If the app remains in the background and is not terminated by the system, upon returning to the active state, the UIViewController goes through the reverse stages:

  1. applicationWillEnterForeground: This method is called in the AppDelegate before the app transitions from the background to the foreground.
  2. applicationDidBecomeActive: This method is called in the AppDelegate after the app has become active again.
  3. viewWillAppear: This method is called before the view controller's view becomes visible. Here, you can update the UI.
  4. viewDidAppear: This method is called after the view controller's view has become visible.

It is important to note that the UIViewController object itself is not removed from memory when minimized, unless it was explicitly unloaded by the system due to resource constraints (which is rare and depends on many factors). The view of the controller can also be unloaded from memory (viewWillUnload, viewDidUnload - methods removed in iOS 6) if it is not needed at the moment and the system needs memory. In this case, the view will be recreated upon the next access.

What happens to UIViewController when the app is… - sobes.tech