Advanced Android Fragments, Tom Opgenorth

1,636
-1

Published on

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

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

No notes for slide

Advanced Android Fragments, Tom Opgenorth

  1. 1. Tom OpgenorthDeveloper / WriterXamarintom.opgenorth@xamarin.comFragments - The Next Step(Advanced Fragments)@topgenorth
  2. 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. 3. Review
  4. 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. 5. Retaining State
  6. 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. 7. - Leonardo da VinciSimplicity is the Ultimate Sophistication
  8. 8. this.RetainInstance = true;
  9. 9. How Does this Impact the FragmentLifecycle?StartOnInflate OnAttachOnCreateOnCreateViewOnActivityCreatedOnStartOnResumeOnPauseOnStopOnDestroyViewOnDestroyOnDetachRunningEnd
  10. 10. • Survives config changes!• Lightweight• Perfect forBackground Process (Threads)Memory intensive ResourcesSharing DataWhat Does This Mean - Exactly?
  11. 11. Demo 1
  12. 12. DialogFragment
  13. 13. Why Use DialogFragment?• Configuration changes are hard on dialogsDialog Should Remain - but the Activity is destroyed• Customizable• “Managed Dialogs” - Old School
  14. 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. 15. Demo 2
  16. 16. PreferenceFragment
  17. 17. PreferenceFragment : Why Do I Care?• Preferred Way for Android 3.0 or Higher• Can Share Across Activities• Allows for HierarchiesPreferenceActivity Does Not
  18. 18. On A Tablet
  19. 19. On a Phone
  20. 20. Demo 3
  21. 21. What Were We Talking About Again?• Keep Fragments around with RetainInstance• DialogFragmentsDialog or EmbeddedModal but not Blocking!• PreferenceFragment
  22. 22. Q & A
  23. 23. THANK YOU

×