SlideShare a Scribd company logo
Tom Opgenorth
Developer / Writer
Xamarin
tom.opgenorth@xamarin.com
Fragments - The Next Step
(Advanced Fragments)
@topgenorth
Topics to Look out For In this Session
• Quick Review of Fragments
• How Fragments can Help Their Host with State
• Not ONE But TWO Fragments :
DialogFragment
PreferenceFragment
Review
What Do We Need to Remember About
Fragments ?
• Fragments Are Modular UI
Think “mini-Activity”
• Hosted in an Activity
Statically - in Layout
Dynamically - at Runtime
• They inflate views (usually)
• They have a lifecycle
Retaining State
• Runtime / Changes kill Activities
State needs to be maintained
• Custom objects to maintain state
Subclass Java.Lang.Object
Override OnRetainNonConfigurationInstance
Check Activity.LastNonConfigurationInstance
But these are DEPRECATED!
Activity State Can Complex
- Leonardo da Vinci
Simplicity is the Ultimate Sophistication
this.RetainInstance = true;
How Does this Impact the Fragment
Lifecycle?
Start
OnInflate OnAttach
OnCreate
OnCreate
View
OnActivity
Created
OnStart
OnResume
OnPause
OnStop
OnDestroy
View
OnDestroy
OnDetachRunning
End
• Survives config changes!
• Lightweight
• Perfect for
Background Process (Threads)
Memory intensive Resources
Sharing Data
What Does This Mean - Exactly?
Demo 1
DialogFragment
Why Use DialogFragment?
• Configuration changes are hard on dialogs
Dialog Should Remain - but the Activity is destroyed
• Customizable
• “Managed Dialogs” - Old School
How Do I Use DialogFragments?
• Subclass DialogFragment
• Override one of the following methods:
OnCreateDialog
• A “proper” dialog will pop up
OnCreateView
• Inflate a View - then embed it
• Modal, but not blocking
Demo 2
Preference
Fragment
PreferenceFragment : Why Do I Care?
• Preferred Way for Android 3.0 or Higher
• Can Share Across Activities
• Allows for Hierarchies
PreferenceActivity Does Not
On A Tablet
On a Phone
Advanced Android Fragments, Tom Opgenorth
Demo 3
What Were We Talking About Again?
• Keep Fragments around with RetainInstance
• DialogFragments
Dialog or Embedded
Modal but not Blocking!
• PreferenceFragment
Q & A
THANK YOU

More Related Content

ODP
CQRS with Event Source in Functional sauce served by Kotlin
PDF
01 what is android
PDF
Create Android App using web view (in tamil)
PDF
Android app - Creating Live Wallpaper (tamil)
PDF
Creating Sample Android App (in tamil)
PDF
Rating Bar in Android Example
PDF
Hardware Interface in Android (in tamil)
PPTX
fragments-activity.pptx
CQRS with Event Source in Functional sauce served by Kotlin
01 what is android
Create Android App using web view (in tamil)
Android app - Creating Live Wallpaper (tamil)
Creating Sample Android App (in tamil)
Rating Bar in Android Example
Hardware Interface in Android (in tamil)
fragments-activity.pptx

Similar to Advanced Android Fragments, Tom Opgenorth (20)

PPTX
Activities vs fragment
PPTX
Lecture #4 activities & fragments
PDF
Game Programming Pattern by Restya
PPTX
Architecting Single Activity Applications (With or Without Fragments)
PPT
Singleton Object Management
PPTX
AISEC 12 april 2012 WP 7.1.1
PPT
Jvm performance tuning
PPTX
YARN Under The Hood
ODP
Javascript training sample
PDF
Gabor Varadi - Reactive State Management with Jetpack Components
PPTX
Reactive state management with Jetpack Components
PDF
Multi screenlab
PPTX
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
KEY
Creating Responsive HTML5 Touch Interfaces
PPTX
Modern app development with Jetpack Compose.pptx
PDF
Introduction to concurrent programming with Akka actors
PDF
Introduction to concurrent programming with akka actors
PPTX
Design pattern (Abstract Factory & Singleton)
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
PDF
Product Management and Systems Thinking
Activities vs fragment
Lecture #4 activities & fragments
Game Programming Pattern by Restya
Architecting Single Activity Applications (With or Without Fragments)
Singleton Object Management
AISEC 12 april 2012 WP 7.1.1
Jvm performance tuning
YARN Under The Hood
Javascript training sample
Gabor Varadi - Reactive State Management with Jetpack Components
Reactive state management with Jetpack Components
Multi screenlab
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Creating Responsive HTML5 Touch Interfaces
Modern app development with Jetpack Compose.pptx
Introduction to concurrent programming with Akka actors
Introduction to concurrent programming with akka actors
Design pattern (Abstract Factory & Singleton)
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
Product Management and Systems Thinking
Ad

More from Xamarin (20)

PDF
Xamarin University Presents: Building Your First Intelligent App with Xamarin...
PDF
Xamarin University Presents: Ship Better Apps with Visual Studio App Center
PDF
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
PDF
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
PDF
Creative Hacking: Delivering React Native App A/B Testing Using CodePush
PDF
Build Better Games with Unity and Microsoft Azure
PDF
Exploring UrhoSharp 3D with Xamarin Workbooks
PDF
Desktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
PDF
Developer’s Intro to Azure Machine Learning
PDF
Customizing Xamarin.Forms UI
PDF
Session 4 - Xamarin Partner Program, Events and Resources
PDF
Session 3 - Driving Mobile Growth and Profitability
PDF
Session 2 - Emerging Technologies in your Mobile Practice
PDF
Session 1 - Transformative Opportunities in Mobile and Cloud
PDF
SkiaSharp Graphics for Xamarin.Forms
PDF
Building Games for iOS, macOS, and tvOS with Visual Studio and Azure
PDF
Intro to Xamarin.Forms for Visual Studio 2017
PDF
Connected Mobile Apps with Microsoft Azure
PDF
Introduction to Xamarin for Visual Studio 2017
PDF
Building Your First iOS App with Xamarin for Visual Studio
Xamarin University Presents: Building Your First Intelligent App with Xamarin...
Xamarin University Presents: Ship Better Apps with Visual Studio App Center
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Creative Hacking: Delivering React Native App A/B Testing Using CodePush
Build Better Games with Unity and Microsoft Azure
Exploring UrhoSharp 3D with Xamarin Workbooks
Desktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
Developer’s Intro to Azure Machine Learning
Customizing Xamarin.Forms UI
Session 4 - Xamarin Partner Program, Events and Resources
Session 3 - Driving Mobile Growth and Profitability
Session 2 - Emerging Technologies in your Mobile Practice
Session 1 - Transformative Opportunities in Mobile and Cloud
SkiaSharp Graphics for Xamarin.Forms
Building Games for iOS, macOS, and tvOS with Visual Studio and Azure
Intro to Xamarin.Forms for Visual Studio 2017
Connected Mobile Apps with Microsoft Azure
Introduction to Xamarin for Visual Studio 2017
Building Your First iOS App with Xamarin for Visual Studio
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
sap open course for s4hana steps from ECC to s4
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Machine Learning_overview_presentation.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Mobile App Security Testing_ A Comprehensive Guide.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
20250228 LYD VKU AI Blended-Learning.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding
sap open course for s4hana steps from ECC to s4
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation
Advanced methodologies resolving dimensionality complications for autism neur...
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
Encapsulation_ Review paper, used for researhc scholars
Machine Learning_overview_presentation.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
A Presentation on Artificial Intelligence
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Advanced Android Fragments, Tom Opgenorth

  • 1. Tom Opgenorth Developer / Writer Xamarin tom.opgenorth@xamarin.com Fragments - The Next Step (Advanced Fragments) @topgenorth
  • 2. Topics to Look out For In this Session • Quick Review of Fragments • How Fragments can Help Their Host with State • Not ONE But TWO Fragments : DialogFragment PreferenceFragment
  • 4. What Do We Need to Remember About Fragments ? • Fragments Are Modular UI Think “mini-Activity” • Hosted in an Activity Statically - in Layout Dynamically - at Runtime • They inflate views (usually) • They have a lifecycle
  • 6. • Runtime / Changes kill Activities State needs to be maintained • Custom objects to maintain state Subclass Java.Lang.Object Override OnRetainNonConfigurationInstance Check Activity.LastNonConfigurationInstance But these are DEPRECATED! Activity State Can Complex
  • 7. - Leonardo da Vinci Simplicity is the Ultimate Sophistication
  • 9. How Does this Impact the Fragment Lifecycle? Start OnInflate OnAttach OnCreate OnCreate View OnActivity Created OnStart OnResume OnPause OnStop OnDestroy View OnDestroy OnDetachRunning End
  • 10. • Survives config changes! • Lightweight • Perfect for Background Process (Threads) Memory intensive Resources Sharing Data What Does This Mean - Exactly?
  • 13. Why Use DialogFragment? • Configuration changes are hard on dialogs Dialog Should Remain - but the Activity is destroyed • Customizable • “Managed Dialogs” - Old School
  • 14. How Do I Use DialogFragments? • Subclass DialogFragment • Override one of the following methods: OnCreateDialog • A “proper” dialog will pop up OnCreateView • Inflate a View - then embed it • Modal, but not blocking
  • 17. PreferenceFragment : Why Do I Care? • Preferred Way for Android 3.0 or Higher • Can Share Across Activities • Allows for Hierarchies PreferenceActivity Does Not
  • 22. What Were We Talking About Again? • Keep Fragments around with RetainInstance • DialogFragments Dialog or Embedded Modal but not Blocking! • PreferenceFragment
  • 23. Q & A