SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
Smashing your Android
App Into Fragments
Tom Opgenorth |
tom@opgenorth.net
A Word From Our Sponsors
1. Whats the Problem?
2. What Are Fragments?
3. How Do I Use Fragments
4. Look at Code!
5. What about Backwards
Compatibility?
Things We’ll Talk About
What Involved
What’s the Problem?
Screen Sizes & Densities
Fragments To The Rescue!
What is Fragment?
A Fragment represents a
behaviour or portion of user
interface in an Activity.
❖ User Interface “modules”
❖ Can share Fragments across different
activity
❖ On Activity can have many
fragments
❖ Different screen sizes have different
layouts
What are Fragments?
❖ Android 3.0 or Higher (well, sort of/not really)
❖ Subclass the Fragment base class
❖ They can load Layout files / Create it’s UI similar to an Activity
❖ There are specialized fragments
❖ Fragments have a lifecycle, just like Activities
Fragment Basics
Fragment Lifecycle
Start
OnInflate
OnAttach
OnCreate
OnCreate
View
OnActivity
Created
OnStart
OnResume
OnPause
OnStop
OnDestroy
View
OnDestroy
OnDetachRunning
End
Fragment Lifecycle (Realistically)
Start
OnInflate
OnAttach
OnCreate
OnCreate
View
OnActivit
y
Created
OnStart
OnResume
OnPause
OnStop
OnDestroy
View
OnDestroy
OnDetachRunning
End
How Do I Create
Fragments?
Fragments Need Help
❖ Must be hosted in an Activity
❖ Activities are Not Directly Aware of
their Fragments
❖ Fragments are aware of their host
Activity
❖ Fragments are not aware of other
Fragments
❖ FragmentManager is the middle man
Fragment Manager
Activity
Fragment
Manager
FragmentFragmentFragmentFragment Find Fragment
1.Activity looking for a Fragment
2. Searches
Fragments
3. Found the request Fragment
Adding a Static Fragment
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
class="net.opgenorth.shakespeare.TitlesFragment"
android:id="@+id/titles_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Adding a Dynamic Fragment
// Make new fragment to show this selection.
DetailsFragment details = new DetailsFragment();
// Execute a transaction, adding the fragment to the FrameLayout.
FragmentTransaction ft = FragmentManager.beginTransaction();
ft.add(Resource.Id.details, details, "details_fragment");
ft.commit();
Show Me The Code!
Backwards Compatibility
Android Support Libraries
❖ A set of code libraries that provide
backwards compatibility and features
to older API levels
❖ Building a Dynamic UI with Fragments - http://developer.android.com/
training/basics/fragments/index.html
❖ Support Libraries - http://developer.android.com/tools/support-library/
index.html
Links / References
Thank You!
Questions?

Contenu connexe

Tendances

Android development orientation for starters v4 seminar
Android development orientation for starters v4   seminarAndroid development orientation for starters v4   seminar
Android development orientation for starters v4 seminarJoemarie Amparo
 
Android development orientation for starters v2
Android development orientation for starters v2Android development orientation for starters v2
Android development orientation for starters v2Joemarie Amparo
 
Android Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectAndroid Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectJoemarie Amparo
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfacesC.o. Nieto
 
Introduction to State Restoration in Flutter
Introduction to State Restoration in FlutterIntroduction to State Restoration in Flutter
Introduction to State Restoration in FlutterDave Chao
 
Liferay UG Meetup #8 - Portal 7.3 + portlets com nodeJS - 2020-03-04
Liferay UG Meetup #8 - Portal 7.3 + portlets com nodeJS - 2020-03-04Liferay UG Meetup #8 - Portal 7.3 + portlets com nodeJS - 2020-03-04
Liferay UG Meetup #8 - Portal 7.3 + portlets com nodeJS - 2020-03-04Fernando Fernández
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesAhsanul Karim
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentRaman Pandey
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basicsAnton Narusberg
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycleAhsanul Karim
 
Android Annotations and RoboGuice
Android Annotations and RoboGuiceAndroid Annotations and RoboGuice
Android Annotations and RoboGuiceJoel Sticha
 
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1Joemarie Amparo
 
Advanced Android Development
Advanced Android DevelopmentAdvanced Android Development
Advanced Android DevelopmentAlfredo Morresi
 

Tendances (20)

Fragments
FragmentsFragments
Fragments
 
Android development orientation for starters v4 seminar
Android development orientation for starters v4   seminarAndroid development orientation for starters v4   seminar
Android development orientation for starters v4 seminar
 
Android development orientation for starters v2
Android development orientation for starters v2Android development orientation for starters v2
Android development orientation for starters v2
 
Android Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectAndroid Development Made Easy - With Sample Project
Android Development Made Easy - With Sample Project
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfaces
 
Introduction to State Restoration in Flutter
Introduction to State Restoration in FlutterIntroduction to State Restoration in Flutter
Introduction to State Restoration in Flutter
 
Liferay UG Meetup #8 - Portal 7.3 + portlets com nodeJS - 2020-03-04
Liferay UG Meetup #8 - Portal 7.3 + portlets com nodeJS - 2020-03-04Liferay UG Meetup #8 - Portal 7.3 + portlets com nodeJS - 2020-03-04
Liferay UG Meetup #8 - Portal 7.3 + portlets com nodeJS - 2020-03-04
 
Flutter
FlutterFlutter
Flutter
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Flutter
FlutterFlutter
Flutter
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
 
Android vs iOS
Android vs iOSAndroid vs iOS
Android vs iOS
 
Android Annotations and RoboGuice
Android Annotations and RoboGuiceAndroid Annotations and RoboGuice
Android Annotations and RoboGuice
 
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
 
Advanced Android Development
Advanced Android DevelopmentAdvanced Android Development
Advanced Android Development
 
SWT - Technical Deep Dive
SWT - Technical Deep DiveSWT - Technical Deep Dive
SWT - Technical Deep Dive
 
Fragment debugging
Fragment debuggingFragment debugging
Fragment debugging
 

Similaire à Smash your Android App into Fragments

Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in androidPrawesh Shrestha
 
[Individual presentation] android fragment
[Individual presentation] android fragment[Individual presentation] android fragment
[Individual presentation] android fragmentGabriele Vecchia
 
Lecture #4 activities &amp; fragments
Lecture #4  activities &amp; fragmentsLecture #4  activities &amp; fragments
Lecture #4 activities &amp; fragmentsVitali Pekelis
 
Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011sullis
 
android development training in mumbai
android development training in mumbaiandroid development training in mumbai
android development training in mumbaifaizrashid1995
 
Functional Requirements Of System Requirements
Functional Requirements Of System RequirementsFunctional Requirements Of System Requirements
Functional Requirements Of System RequirementsLaura Arrigo
 
Android design patterns
Android design patternsAndroid design patterns
Android design patternsPlatty Soft
 
Usability Workshop at Lillebaelt Academy
Usability Workshop at Lillebaelt AcademyUsability Workshop at Lillebaelt Academy
Usability Workshop at Lillebaelt AcademyDániel Góré
 
Guidelines for Android application design.pptx
Guidelines for Android application design.pptxGuidelines for Android application design.pptx
Guidelines for Android application design.pptxdebasish duarah
 
[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Android[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Androidrizki adam kurniawan
 
ItemMirror, XML & The Promise of Information Integration
ItemMirror, XML & The Promise of Information IntegrationItemMirror, XML & The Promise of Information Integration
ItemMirror, XML & The Promise of Information Integrationkeepingfoundthingsfound
 
Screen-Capturing, Screen-Casting, and Screen Sharing for the Budget Friendly ...
Screen-Capturing, Screen-Casting, and Screen Sharing for the Budget Friendly ...Screen-Capturing, Screen-Casting, and Screen Sharing for the Budget Friendly ...
Screen-Capturing, Screen-Casting, and Screen Sharing for the Budget Friendly ...Staci Trekles
 
Web valley talk - usability, visualization and mobile app development
Web valley talk - usability, visualization and mobile app developmentWeb valley talk - usability, visualization and mobile app development
Web valley talk - usability, visualization and mobile app developmentEamonn Maguire
 

Similaire à Smash your Android App into Fragments (20)

fragments-activity.pptx
fragments-activity.pptxfragments-activity.pptx
fragments-activity.pptx
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
[Individual presentation] android fragment
[Individual presentation] android fragment[Individual presentation] android fragment
[Individual presentation] android fragment
 
Apocalypse Soon
Apocalypse SoonApocalypse Soon
Apocalypse Soon
 
Vp all slides
Vp   all slidesVp   all slides
Vp all slides
 
Lecture #4 activities &amp; fragments
Lecture #4  activities &amp; fragmentsLecture #4  activities &amp; fragments
Lecture #4 activities &amp; fragments
 
Screencasting for the budget-friendly teacher
Screencasting for the budget-friendly teacherScreencasting for the budget-friendly teacher
Screencasting for the budget-friendly teacher
 
Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011
 
android development training in mumbai
android development training in mumbaiandroid development training in mumbai
android development training in mumbai
 
Chapter 1-Note.docx
Chapter 1-Note.docxChapter 1-Note.docx
Chapter 1-Note.docx
 
Functional Requirements Of System Requirements
Functional Requirements Of System RequirementsFunctional Requirements Of System Requirements
Functional Requirements Of System Requirements
 
Android design patterns
Android design patternsAndroid design patterns
Android design patterns
 
Fragments In Android.pptx
Fragments In Android.pptxFragments In Android.pptx
Fragments In Android.pptx
 
Usability Workshop at Lillebaelt Academy
Usability Workshop at Lillebaelt AcademyUsability Workshop at Lillebaelt Academy
Usability Workshop at Lillebaelt Academy
 
Guidelines for Android application design.pptx
Guidelines for Android application design.pptxGuidelines for Android application design.pptx
Guidelines for Android application design.pptx
 
[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Android[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Android
 
Mobile Apps Testing - Part 2
Mobile Apps Testing - Part 2Mobile Apps Testing - Part 2
Mobile Apps Testing - Part 2
 
ItemMirror, XML & The Promise of Information Integration
ItemMirror, XML & The Promise of Information IntegrationItemMirror, XML & The Promise of Information Integration
ItemMirror, XML & The Promise of Information Integration
 
Screen-Capturing, Screen-Casting, and Screen Sharing for the Budget Friendly ...
Screen-Capturing, Screen-Casting, and Screen Sharing for the Budget Friendly ...Screen-Capturing, Screen-Casting, and Screen Sharing for the Budget Friendly ...
Screen-Capturing, Screen-Casting, and Screen Sharing for the Budget Friendly ...
 
Web valley talk - usability, visualization and mobile app development
Web valley talk - usability, visualization and mobile app developmentWeb valley talk - usability, visualization and mobile app development
Web valley talk - usability, visualization and mobile app development
 

Dernier

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Dernier (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Smash your Android App into Fragments