Getting Dirty with Android

1,707 views

Published on

Key concepts that every Android developer needs to understand to be successful.

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

No Downloads
Views
Total views
1,707
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Getting Dirty with Android

  1. 1. Getting Dirty With Android<br />
  2. 2. Brent Edwards<br />Senior Consultant with Magenic<br />BrentE@magenic.com<br />@brentledwards<br />brentedwards.net<br />
  3. 3. What We Will Cover<br />Menus<br />Layout<br />Styles<br />Lifecycle Management<br />AsyncTask<br />All while building a sample app<br />
  4. 4. Assumptions<br />Basic understanding of…<br />Android<br />Activities and Intents<br />Resources<br />
  5. 5. Menus<br />
  6. 6. Menus<br />3 Flavors<br />Options Menu<br />Primary Menu Type<br />Menu Button Pressed<br />First 5-6 Options -> Icon Menu<br />When 7+ options, Option 6+ -> Expanded Menu<br />Context Menu<br />Long Press<br />Sub Menu<br />
  7. 7. Menus<br />Define menus in XML<br />res/menu/<br />Inflate the XML resource in code<br />
  8. 8. Menus<br />[Demo]<br />
  9. 9. Layout<br />
  10. 10. Layout<br />Defines what the UI looks like<br />Where views are placed<br />How big views are<br />How views flow<br />Made up of nested views<br />
  11. 11. Layout<br />2 Ways to define layout<br />XML<br />Provides most flexibility<br />Better separation of UI from logic<br />Easier to visualize<br />Programmatically<br />Can be more difficult<br />Best when coupled with XML and LayoutInflater<br />
  12. 12. Layout - XML<br />Valid XML file<br />Each node maps to a view instance<br />Attributes set properties on the view<br />Layout File Convention<br />Have .xml extension<br />Named with all lowercase<br />Placed in res/layout/ folder<br />
  13. 13. Layout<br />Most Useful Layout Objects<br />LinearLayout<br />RelativeLayout<br />
  14. 14. Layout - LinearLayout<br />Views are stacked [horizontally|vertically]<br />
  15. 15. Layout - LinearLayout<br />Why it is so useful<br />Simple to use<br />Easy to understand at a glance<br />Can leverage weight for children to scale proportionally<br />
  16. 16. LinearLayout<br />[Demo]<br />
  17. 17. Layout - RelativeLayout<br />Views specify their position relative to parent, other views or both<br />
  18. 18. Layout - RelativeLayout<br />Why it is so useful<br />Very versatile<br />Scales very well<br />Handles rotation easily<br />
  19. 19. RelativeLayout<br />[Demo]<br />
  20. 20. Styles<br />
  21. 21. Styles<br />Specifies look and format for views<br />Separates design from content<br />Collection of properties<br />Font Size<br />Font Color<br />Background Color<br />Padding<br />Margin<br />Much more<br />
  22. 22. Styles<br />Adds consistency to UI<br />Similar to CSS<br />
  23. 23. Styles<br />Styles file convention<br />Have .xml extension<br />style.xml<br />Placed in res/values/<br />
  24. 24. Style<br />[Demo]<br />
  25. 25. Lifecycle Management<br />
  26. 26. Lifecycle Management<br />Applications have a lifecycle<br />Essentially Three States<br />Active / Running<br />Paused<br />Stopped<br />
  27. 27. Lifecycle Management<br />
  28. 28. Lifecycle Management<br />Stopped Activities can be killed<br />Then recreated when brought to front<br />Activities with state need to be serialized<br />onPause()<br />onSaveInstanceState()<br />
  29. 29. Lifecycle Management<br />[Demo]<br />
  30. 30. AsyncTask<br />
  31. 31. AsyncTask<br />Tasks run asynchronously<br />Doesn’t freeze UI<br />Good for long running tasks<br />Web requests<br />
  32. 32. AsyncTask<br />Defined by 3 generic types<br />Params<br />Progress<br />Result<br />
  33. 33. AsyncTask<br />4 Steps<br />onPreExecute<br />Executes on UI thread<br />doInBackground<br />Executes the actual task on background thread<br />onProgressUpdate<br />Optionally updates user on progress on UI thread<br />onPostExecute<br />Executes on UI thread<br />
  34. 34. AsyncTask<br />Rules<br />Task must be created in UI thread<br />execute must be invoked from UI thread<br />Tasks can only be executed once<br />Don’t call onPreExecute, onPostExecute, doInBackground or onProgressUpdate manually<br />
  35. 35. AsyncTask<br />[Demo]<br />
  36. 36. Dialogs<br />
  37. 37. Dialogs<br />Types<br />AlertDialog<br />ProgressDialog<br />DatePickerDialog<br />TimePickerDialog<br />Override Dialog class to create Custom Dialogs<br />
  38. 38. Dialogs<br />To show a Dialog<br />Simple way<br />More complex way<br />Override onCreateDialog(int)<br />Call showDialog(int)<br />
  39. 39. Dialogs<br />[Demo]<br />
  40. 40. Valuable Links<br />Fundamentals<br />http://developer.android.com/guide/topics/fundamentals.html<br />Menus<br />http://developer.android.com/guide/topics/ui/menus.html<br />Layout<br />http://developer.android.com/guide/topics/ui/declaring-layout.html<br />Styles<br />http://developer.android.com/guide/topics/ui/themes.html<br />AsyncTask<br />http://developer.android.com/reference/android/os/AsyncTask.html<br />Dialogs<br />http://developer.android.com/guide/topics/ui/dialogs.html<br />
  41. 41. Questions?<br />
  42. 42. Brent Edwards<br />Senior Consultant with Magenic<br />BrentE@magenic.com<br />@brentledwards<br />brentedwards.net<br />

×