SlideShare a Scribd company logo
Activity Lifecycle,
Fragment and
Fragment Lifecycle
By Dhruv Shah
Activity
An Activity is said to be the presentation layer of
our applications.
It provides a window in which the app draws its UI.
Activity
Lifecycl
e
Activity Lifecycle Callbacks
Fragments
A Fragment represents a reusable portion of your
app's User Interface.
It’s a piece of an activity which enable more
modular activity design.
In simple words,it can be referred to as a sub-
activity.
WHY DO WE USE FRAGMENTS?
● To make apps lightweight.
● To construct a UI component that will be used by multiple
activities.
● To make efficient use of an activity to display different layouts.
● Flexibility to control different parts of the activity separately
because Fragments have their own layout,events and a
complete life cycle.
Fragment
Lifecycle
Fragment call backs
Activity &
Fragment
Lifecycle
On Creation
Activity &
Fragment
Lifecycle
On Deletion
Navigation Component
By Vriddhi Gupta
Boring Theory (But important)
The Navigation component consists of three key parts that are described below:
● Navigation graph: An XML resource that contains all navigation-related information in one
centralized location. This includes all of the individual content areas within your app, called
destinations, as well as the possible paths that a user can take through your app.
● NavHost: An empty container that displays destinations from your navigation graph. The
Navigation component contains a default NavHost implementation, NavHostFragment, that
displays fragment destinations.
● NavController: An object that manages app navigation within a NavHost. The NavController
orchestrates the swapping of destination content in the NavHost as users move throughout
your app.
Navigation Graph
Navigation Graph
1. Navigation occurs between your app's destinations—that is, anywhere in your app
to which users can navigate. These destinations are connected via actions.
2. A navigation graph is a resource file that contains all of your destinations and
actions. The graph represents all of your app's navigation paths.
➔ Destinations are the different content areas or fragments in your app.
➔ Actions are logical connections between your destinations that represent paths
that users can take. So it is used to navigate from one fragment to another.
An
Example
Navigate to a
destination
NavController
1. Navigating to a destination is done using a NavController, an object that manages app navigation within a
NavHost. Each NavHost has its own corresponding NavController. NavController provides a few different
ways to navigate to a destination, which are further described in the sections below.
2. To retrieve the NavController for a fragment, activity, or view, use one of the following methods:
Use Safe Args to navigate with type-safety
1. The recommended way to navigate between destinations is to use the Safe Args Gradle plugin. This plugin
generates simple object and builder classes that enable type-safe navigation between destinations. Safe
Args is recommended both for navigating as well as passing data between destinations.
Kotlin:
● Fragment.findNavController()
● View.findNavController()
● Activity.findNavController(viewId: Int)
NavHost
A host is a single context or container for navigation via a NavController.
Navigation hosts must:
● Handle saving and restoring their controller's state
● Call Navigation.setViewNavController on their root view
● Route system Back button events to the NavController either by manually calling
NavController.popBackStack or by calling NavHostController.setOnBackPressedDispatcher
when constructing the NavController.

More Related Content

Similar to Android Study Jam 4 - Introduction to Fragment, Activity & Fragment Lifecycle & Navigation Component | GDSC VJTI

Android beginners David
Android beginners DavidAndroid beginners David
Android beginners David
Arun David Johnson R
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
Chandrakant Divate
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
Aly Abdelkareem
 
Chapter 1-Note.docx
Chapter 1-Note.docxChapter 1-Note.docx
Chapter 1-Note.docx
TigistTilahun1
 
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
Amr Elghadban (AmrAngry)
 
Unit2
Unit2Unit2
A Single activity app with Jetpack's Navigation Component
A Single activity app with Jetpack's Navigation ComponentA Single activity app with Jetpack's Navigation Component
A Single activity app with Jetpack's Navigation Component
Boonya Kitpitak
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentals
Amr Salman
 
Intro to AngularJS
Intro to AngularJS Intro to AngularJS
Intro to AngularJS
Sparkhound Inc.
 
Android Navigation Component
Android Navigation ComponentAndroid Navigation Component
Android Navigation Component
Łukasz Ciupa
 
Mobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdfMobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdf
AbdullahMunir32
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1Hussain Behestee
 
Kotlin for Android App Development Presentation
Kotlin for Android App Development PresentationKotlin for Android App Development Presentation
Kotlin for Android App Development Presentation
Knoldus Inc.
 
Swing components
Swing components Swing components
Swing components
Sameenafathima4
 
Beginning android
Beginning android Beginning android
Beginning android
Igor R
 
"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2
Tadas Jurelevičius
 
Android application development
Android application developmentAndroid application development
Android application development
Md. Mujahid Islam
 
hema ppt (2).pptx
hema ppt (2).pptxhema ppt (2).pptx
hema ppt (2).pptx
balasekaran5
 
Android Introduction by Kajal
Android Introduction by KajalAndroid Introduction by Kajal
Android Introduction by Kajal
Kajal Kucheriya Jain
 

Similar to Android Study Jam 4 - Introduction to Fragment, Activity & Fragment Lifecycle & Navigation Component | GDSC VJTI (20)

Android beginners David
Android beginners DavidAndroid beginners David
Android beginners David
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Chapter 1-Note.docx
Chapter 1-Note.docxChapter 1-Note.docx
Chapter 1-Note.docx
 
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
 
Unit2
Unit2Unit2
Unit2
 
A Single activity app with Jetpack's Navigation Component
A Single activity app with Jetpack's Navigation ComponentA Single activity app with Jetpack's Navigation Component
A Single activity app with Jetpack's Navigation Component
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentals
 
Intro to AngularJS
Intro to AngularJS Intro to AngularJS
Intro to AngularJS
 
Android Navigation Component
Android Navigation ComponentAndroid Navigation Component
Android Navigation Component
 
Mobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdfMobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdf
 
Android
AndroidAndroid
Android
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
Kotlin for Android App Development Presentation
Kotlin for Android App Development PresentationKotlin for Android App Development Presentation
Kotlin for Android App Development Presentation
 
Swing components
Swing components Swing components
Swing components
 
Beginning android
Beginning android Beginning android
Beginning android
 
"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2
 
Android application development
Android application developmentAndroid application development
Android application development
 
hema ppt (2).pptx
hema ppt (2).pptxhema ppt (2).pptx
hema ppt (2).pptx
 
Android Introduction by Kajal
Android Introduction by KajalAndroid Introduction by Kajal
Android Introduction by Kajal
 

Recently uploaded

CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
obonagu
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
01-GPON Fundamental fttx ftth basic .pptx
01-GPON Fundamental fttx ftth basic .pptx01-GPON Fundamental fttx ftth basic .pptx
01-GPON Fundamental fttx ftth basic .pptx
benykoy2024
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 

Recently uploaded (20)

CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
01-GPON Fundamental fttx ftth basic .pptx
01-GPON Fundamental fttx ftth basic .pptx01-GPON Fundamental fttx ftth basic .pptx
01-GPON Fundamental fttx ftth basic .pptx
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 

Android Study Jam 4 - Introduction to Fragment, Activity & Fragment Lifecycle & Navigation Component | GDSC VJTI

  • 2. Activity An Activity is said to be the presentation layer of our applications. It provides a window in which the app draws its UI.
  • 5. Fragments A Fragment represents a reusable portion of your app's User Interface. It’s a piece of an activity which enable more modular activity design. In simple words,it can be referred to as a sub- activity.
  • 6.
  • 7. WHY DO WE USE FRAGMENTS? ● To make apps lightweight. ● To construct a UI component that will be used by multiple activities. ● To make efficient use of an activity to display different layouts. ● Flexibility to control different parts of the activity separately because Fragments have their own layout,events and a complete life cycle.
  • 10.
  • 14. Boring Theory (But important) The Navigation component consists of three key parts that are described below: ● Navigation graph: An XML resource that contains all navigation-related information in one centralized location. This includes all of the individual content areas within your app, called destinations, as well as the possible paths that a user can take through your app. ● NavHost: An empty container that displays destinations from your navigation graph. The Navigation component contains a default NavHost implementation, NavHostFragment, that displays fragment destinations. ● NavController: An object that manages app navigation within a NavHost. The NavController orchestrates the swapping of destination content in the NavHost as users move throughout your app.
  • 16. Navigation Graph 1. Navigation occurs between your app's destinations—that is, anywhere in your app to which users can navigate. These destinations are connected via actions. 2. A navigation graph is a resource file that contains all of your destinations and actions. The graph represents all of your app's navigation paths. ➔ Destinations are the different content areas or fragments in your app. ➔ Actions are logical connections between your destinations that represent paths that users can take. So it is used to navigate from one fragment to another.
  • 19. NavController 1. Navigating to a destination is done using a NavController, an object that manages app navigation within a NavHost. Each NavHost has its own corresponding NavController. NavController provides a few different ways to navigate to a destination, which are further described in the sections below. 2. To retrieve the NavController for a fragment, activity, or view, use one of the following methods: Use Safe Args to navigate with type-safety 1. The recommended way to navigate between destinations is to use the Safe Args Gradle plugin. This plugin generates simple object and builder classes that enable type-safe navigation between destinations. Safe Args is recommended both for navigating as well as passing data between destinations. Kotlin: ● Fragment.findNavController() ● View.findNavController() ● Activity.findNavController(viewId: Int)
  • 20. NavHost A host is a single context or container for navigation via a NavController. Navigation hosts must: ● Handle saving and restoring their controller's state ● Call Navigation.setViewNavController on their root view ● Route system Back button events to the NavController either by manually calling NavController.popBackStack or by calling NavHostController.setOnBackPressedDispatcher when constructing the NavController.