SlideShare a Scribd company logo
1 of 13
Download to read offline
Unit 4—Lesson 2:
App Anatomy and Life Cycle
App life cycle
Not running
Inactive
Active
Background
Suspended
Foreground
Background
Break down the delegate
Did Finish Launching

Will Resign Active

Did Enter Background

Will Enter Foreground

Did Become Active

Will Terminate
Did Finish Launching
UIApplicationDelegate protocol methods
App has finished launching

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}
Override point for customization after app launch
Will Resign Active
UIApplicationDelegate protocol methods
App is about to move from active to inactive state

func applicationWillResignActive(_ application: UIApplication) {
}
Can occur for certain types of temporary interruptions (such as an incoming phone
call or SMS message)

Can occur when the user quits the app and it begins the transition to the 

background state

Use to pause ongoing tasks, disable timers, and invalidate graphics rendering
callbacks
Did Enter Background
UIApplicationDelegate protocol methods
App is about to move from active to inactive state

func applicationDidEnterBackground(_ application: UIApplication) {
}
Use to release shared resources, save user data, invalidate timers, and store
enough application state information to restore your application to its current state
in case it’s terminated later

If your application supports background execution, this method is called instead
of applicationWillTerminate: when the user quits
Will Enter Foreground
UIApplicationDelegate protocol methods
Called immediately before the applicationDidBecomeActive function

func applicationWillEnterForeground(_ application: UIApplication) {
}
Called as part of transition from the background to the active state

Can be used to undo many of the changes made on entering the background
Did Become Active
UIApplicationDelegate protocol methods
App was launched by the user or system

func applicationDidBecomeActive(_ application: UIApplication) {
}
Restart any tasks that were paused (or not yet started) while the app was inactive

If the app was previously in the background, optionally refresh the user interface
Will Terminate
UIApplicationDelegate protocol methods
App is about to be terminated

func applicationWillTerminate(_ application: UIApplication) {
}
Save data if appropriate

See also applicationDidEnterBackground:
Which methods should I use?
Start with the methods that will run when launching, reopening, or closing 

your app

• applicationDidFinishLaunchingWithOptions
• applicationWillResignActive
• applicationDidBecomeActive
Take advantage of the other three delegate methods as you become more experienced
App Anatomy and Life Cycle
Unit 4—Lesson 2
Learn more about the different life cycle states and the delegate hooks for
executing logic as the app moves through each state.
Lab: App Event Count
Unit 4—Lesson 2
Create an app that provides a visual representation of the app life cycle. 

Your app will update labels on the view when different delegate methods are called.
© 2017 Apple Inc. 

This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.

More Related Content

Similar to App anatomy and life cycle

android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
aswinbiju1652
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
Hussain Behestee
 
android activity
android activityandroid activity
android activity
Deepa Rani
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
DHIRAJ PRAVIN
 
Windows phone 8 session 9
Windows phone 8 session 9Windows phone 8 session 9
Windows phone 8 session 9
hitesh chothani
 
Threads handlers and async task, widgets - day8
Threads   handlers and async task, widgets - day8Threads   handlers and async task, widgets - day8
Threads handlers and async task, widgets - day8
Utkarsh Mankad
 

Similar to App anatomy and life cycle (20)

Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116
 
Bcsf13a019_mcqs_ead
Bcsf13a019_mcqs_eadBcsf13a019_mcqs_ead
Bcsf13a019_mcqs_ead
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 
android activity
android activityandroid activity
android activity
 
Certification preparation - Error Handling and Troubleshooting recap.pptx
Certification preparation - Error Handling and Troubleshooting recap.pptxCertification preparation - Error Handling and Troubleshooting recap.pptx
Certification preparation - Error Handling and Troubleshooting recap.pptx
 
Android application development
Android application developmentAndroid application development
Android application development
 
Android
AndroidAndroid
Android
 
Compose Camp by GDSC NSUT
Compose Camp by GDSC NSUTCompose Camp by GDSC NSUT
Compose Camp by GDSC NSUT
 
INTELLIGENT TOURIST GUIDE SYSTEM CHAPTER 3
INTELLIGENT TOURIST GUIDE SYSTEM CHAPTER 3INTELLIGENT TOURIST GUIDE SYSTEM CHAPTER 3
INTELLIGENT TOURIST GUIDE SYSTEM CHAPTER 3
 
Lab3-Android
Lab3-AndroidLab3-Android
Lab3-Android
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
fragments-activity.pptx
fragments-activity.pptxfragments-activity.pptx
fragments-activity.pptx
 
Windows phone 8 session 9
Windows phone 8 session 9Windows phone 8 session 9
Windows phone 8 session 9
 
User Forms & API integration
User Forms & API integrationUser Forms & API integration
User Forms & API integration
 
Implementation of agile methodology in mobile automation testing
Implementation of agile methodology in mobile automation testingImplementation of agile methodology in mobile automation testing
Implementation of agile methodology in mobile automation testing
 
Threads handlers and async task, widgets - day8
Threads   handlers and async task, widgets - day8Threads   handlers and async task, widgets - day8
Threads handlers and async task, widgets - day8
 

More from SV.CO (20)

Handout level-1-module-1
Handout   level-1-module-1Handout   level-1-module-1
Handout level-1-module-1
 
Persistence And Documents
Persistence And DocumentsPersistence And Documents
Persistence And Documents
 
Building complex input screens
Building complex input screensBuilding complex input screens
Building complex input screens
 
Working with the Web: 
Decoding JSON
Working with the Web: 
Decoding JSONWorking with the Web: 
Decoding JSON
Working with the Web: 
Decoding JSON
 
Saving Data
Saving DataSaving Data
Saving Data
 
Alerts notification
Alerts notificationAlerts notification
Alerts notification
 
UI Dynamics
UI DynamicsUI Dynamics
UI Dynamics
 
Practical animation
Practical animationPractical animation
Practical animation
 
Segues and navigation controllers
Segues and navigation controllersSegues and navigation controllers
Segues and navigation controllers
 
Camera And Email
Camera And EmailCamera And Email
Camera And Email
 
Scroll views
Scroll viewsScroll views
Scroll views
 
Intermediate table views
Intermediate table viewsIntermediate table views
Intermediate table views
 
Table views
Table viewsTable views
Table views
 
Closures
ClosuresClosures
Closures
 
Protocols
ProtocolsProtocols
Protocols
 
Extensions
ExtensionsExtensions
Extensions
 
Gestures
GesturesGestures
Gestures
 
View controller life cycle
View controller life cycleView controller life cycle
View controller life cycle
 
Controls in action
Controls in actionControls in action
Controls in action
 
Auto layout and stack views
Auto layout and stack viewsAuto layout and stack views
Auto layout and stack views
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptx
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 

App anatomy and life cycle

  • 1. Unit 4—Lesson 2: App Anatomy and Life Cycle
  • 2. App life cycle Not running Inactive Active Background Suspended Foreground Background
  • 3. Break down the delegate Did Finish Launching Will Resign Active Did Enter Background Will Enter Foreground Did Become Active Will Terminate
  • 4. Did Finish Launching UIApplicationDelegate protocol methods App has finished launching func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { return true } Override point for customization after app launch
  • 5. Will Resign Active UIApplicationDelegate protocol methods App is about to move from active to inactive state func applicationWillResignActive(_ application: UIApplication) { } Can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) Can occur when the user quits the app and it begins the transition to the 
 background state Use to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks
  • 6. Did Enter Background UIApplicationDelegate protocol methods App is about to move from active to inactive state func applicationDidEnterBackground(_ application: UIApplication) { } Use to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it’s terminated later If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits
  • 7. Will Enter Foreground UIApplicationDelegate protocol methods Called immediately before the applicationDidBecomeActive function func applicationWillEnterForeground(_ application: UIApplication) { } Called as part of transition from the background to the active state Can be used to undo many of the changes made on entering the background
  • 8. Did Become Active UIApplicationDelegate protocol methods App was launched by the user or system func applicationDidBecomeActive(_ application: UIApplication) { } Restart any tasks that were paused (or not yet started) while the app was inactive If the app was previously in the background, optionally refresh the user interface
  • 9. Will Terminate UIApplicationDelegate protocol methods App is about to be terminated func applicationWillTerminate(_ application: UIApplication) { } Save data if appropriate See also applicationDidEnterBackground:
  • 10. Which methods should I use? Start with the methods that will run when launching, reopening, or closing 
 your app • applicationDidFinishLaunchingWithOptions • applicationWillResignActive • applicationDidBecomeActive Take advantage of the other three delegate methods as you become more experienced
  • 11. App Anatomy and Life Cycle Unit 4—Lesson 2 Learn more about the different life cycle states and the delegate hooks for executing logic as the app moves through each state.
  • 12. Lab: App Event Count Unit 4—Lesson 2 Create an app that provides a visual representation of the app life cycle. Your app will update labels on the view when different delegate methods are called.
  • 13. © 2017 Apple Inc. This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.