Your SlideShare is downloading. ×

Advanced Android Fragments, Tom Opgenorth

1,271

Published on

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,271
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
6
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Tom OpgenorthDeveloper / WriterXamarintom.opgenorth@xamarin.comFragments - 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 :DialogFragmentPreferenceFragment
  • 3. Review
  • 4. What Do We Need to Remember AboutFragments ?• Fragments Are Modular UIThink “mini-Activity”• Hosted in an ActivityStatically - in LayoutDynamically - at Runtime• They inflate views (usually)• They have a lifecycle
  • 5. Retaining State
  • 6. • Runtime / Changes kill ActivitiesState needs to be maintained• Custom objects to maintain stateSubclass Java.Lang.ObjectOverride OnRetainNonConfigurationInstanceCheck Activity.LastNonConfigurationInstanceBut these are DEPRECATED!Activity State Can Complex
  • 7. - Leonardo da VinciSimplicity is the Ultimate Sophistication
  • 8. this.RetainInstance = true;
  • 9. How Does this Impact the FragmentLifecycle?StartOnInflate OnAttachOnCreateOnCreateViewOnActivityCreatedOnStartOnResumeOnPauseOnStopOnDestroyViewOnDestroyOnDetachRunningEnd
  • 10. • Survives config changes!• Lightweight• Perfect forBackground Process (Threads)Memory intensive ResourcesSharing DataWhat Does This Mean - Exactly?
  • 11. Demo 1
  • 12. DialogFragment
  • 13. Why Use DialogFragment?• Configuration changes are hard on dialogsDialog 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 upOnCreateView• Inflate a View - then embed it• Modal, but not blocking
  • 15. Demo 2
  • 16. PreferenceFragment
  • 17. PreferenceFragment : Why Do I Care?• Preferred Way for Android 3.0 or Higher• Can Share Across Activities• Allows for HierarchiesPreferenceActivity Does Not
  • 18. On A Tablet
  • 19. On a Phone
  • 20. Demo 3
  • 21. What Were We Talking About Again?• Keep Fragments around with RetainInstance• DialogFragmentsDialog or EmbeddedModal but not Blocking!• PreferenceFragment
  • 22. Q & A
  • 23. THANK YOU

×