Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Activities 101

Android Activities 101

Slide deck from GDG Hydroid event on April 20, 2013 at Google Hyderabad on Android Activities.

Mustafa Ali

April 20, 2013
Tweet

More Decks by Mustafa Ali

Other Decks in Technology

Transcript

  1. Mustafa  Ali   Senior  Android  Engineer,  Technical  Lead    

        Building  apps  since  v1.6  came  out   MS  from  IIIT  Hyderabad   Who  am  I?  
  2. *  Activity  basics   *  Creating  simple  user  interfaces  

    *  Activity  lifecycle   *  Passing  data  between  activities   *  Navigating  between  activities   *  Supporting  multiple  orientations  and  locales     Agenda  
  3. *  Application  component  that  provides  a  screen  with   which

     users  can  interact   *  Each  activity  is  given  a  window  to  draw  its  user   interface   *  Navigating  between  activities  is  managed  by  the   “Back  Stack”   *  Activities  can  send  and  receive  data  to  and  from  other   activities   Activity  Basics  
  4. *  Dedicated  piece  of  real  estate  at  the  top  of

     each   screen  that  is  generally  persistent  throughout  the  app   *  Provides  user  actions  and  navigation  modes   *  Provides  consistent  navigation  across  different   applications   *  Makes  key  actions  for  the  activity  prominent  and   accessible  to  the  user  in  a  predictable  way   Action  Bar  
  5. *  Introduced  in  Android  3.0  (API  level  11)   * 

    Included  automatically  in  all  activities  that  use  the   Theme.Holo  or  one  of  its  descendants   *  Use  the  Android  Compatibility  Library  to  support   older  versions   *  Can  also  use  ActionBarSherlock   Action  Bar  
  6. *  Define  the  visual  structure  for  a  user  interface  

    *  Can  be  declared  in  XML   *  Can  also  be  created  programmatically   *  Commonly  used  layouts     *  Linear  Layout   *  Relative  Layout   Layouts  
  7. *  Button   *  Text  field   *  Checkbox  

    *  Radio  button   *  Toggle  button   *  Spinner   *  Pickers   Input  Controls  
  8. *  Primitive  types     *  Can  be  passed  easily

     using  intent  extras   *  Custom  types   *  Can  be  passed  using  the  Parcelable  interface   Passing  data  between  activities  
  9. *  Custom  types   1.  Implement  android.os.Parcelable 2.  Override  writeToParcel(…)

    3.  Create  a  CREATOR Passing  data  between  Activities  
  10. *  Starting  one  activity  from  another   *  startActivity(…) * 

    Starting  an  activity  for  result   *  startActivityForResult(…) Navigating  between  Activities  
  11. *  Android  automatically  adapts  your  layout  for  you   * 

    Gives  you  the  flexibility  to  have  a  different  layouts  as   well   1.  Create  a  folder  layout-­‐land   2.  Name  of  the  layout  file  should  be  the  same   3.  Ids  of  the  views  in  the  layout  files  should  be  the  same   Supporting  multiple  orientations  
  12. *  Important  when  you  audience  is  spread  across   multiple

     locations   *  Use  Resource-­‐Switching   Supporting  multiple  locales  
  13. *  Android  resources  -­‐  developer.android.com   *  StackOverflow.com   * 

    Hydroid  community  on  G+   Get  in  touch!              profiles.google.com/mustafa01ali              @CodeTweetRepeat   Need  help?