Android Developer Meetup


Published on

This meetup discussed different concepts for building Android applications for multiple versions and devices out on the market today. This included the ability to take advantage of new 2.0 and 2.1 features while still supporting 1.x users in the same binary.

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Android Developer Meetup

  1. 1. Build One, Ship to Many March 3, 2010 Mike Novak, Medialets
  2. 2. Agenda <ul><ul><li>Introduction </li></ul></ul><ul><ul><li>What's available to developers?  </li></ul></ul><ul><ul><li>Quick overview of application components </li></ul></ul><ul><ul><li>Leveraging resources for multiple versions </li></ul></ul><ul><ul><li>Isolating new API features from older versions </li></ul></ul><ul><ul><li>Closing remarks </li></ul></ul><ul><ul><li>Questions </li></ul></ul>
  3. 3. Introduction Developer Resources: <ul><ul><li> </li></ul></ul><ul><ul><li>Android Mailing Lists (Google Groups) </li></ul></ul><ul><ul><li>IRC (Internet Relay Chat) </li></ul></ul><ul><ul><ul><li>#android-dev - weekly office hours Thursday 8 PM Eastern / 5 PM Pacific </li></ul></ul></ul><ul><ul><li>For the curious... </li></ul></ul>
  4. 4. What's available to developers? <ul><li>Android 2.0 Highlights </li></ul><ul><ul><li>Accounts API </li></ul></ul><ul><ul><li>Bluetooth API </li></ul></ul><ul><ul><li>Contacts API </li></ul></ul><ul><li>Android 2.1 Highlights </li></ul><ul><ul><li>Live Wallpapers </li></ul></ul><ul><ul><li>Signal strength callback </li></ul></ul><ul><ul><li>Data connection callback </li></ul></ul>Complete release notes at
  5. 5. Why support Android 1.x? *Note: Android 2.x support is starting to gain some ground on devices that shipped with 1.x
  6. 6. Quick Overview - App Layout <ul><ul><li>assets/ - when you need raw byte access </li></ul></ul><ul><ul><li>bin/ - output of the project build </li></ul></ul><ul><ul><li>gen/ - Android generated classes </li></ul></ul><ul><ul><li>libs/ - external libraries to include </li></ul></ul><ul><ul><li>res/ - project resources (i.e. drawable, layouts)  </li></ul></ul><ul><ul><li>AndroidManifest.xml - Application manifest </li></ul></ul><ul><ul><li>build.xml - Ant build script generated by the android tool </li></ul></ul>
  7. 7. Specifying Alternate Resources <ul><ul><li>Many configuration options to limit resources for a specific version, device, screen, language, and input type. </li></ul></ul><ul><ul><li>Tonight we will focus on the following: </li></ul></ul><ul><ul><ul><li>Version specific resources for new SDK features. </li></ul></ul></ul><ul><ul><ul><li>Different screen pixel density configurations.  </li></ul></ul></ul>For more information:
  8. 8. A Few Important Notes... <ul><ul><li>Remember your target SDK version and min SDK version do not have to be the same. </li></ul></ul><ul><ul><li>Creating a receiver for a 2.x intent will not break in 1.x, it just won't be executed. </li></ul></ul><ul><ul><li>Using the `am` command on the device/emulator shell you can 'mock' a broadcast. </li></ul></ul><ul><ul><li>  Always test your app on all versions you support! </li></ul></ul>
  9. 9. Initialization on Demand Holder Credit: Josh Guilfoye - <ul><ul><li>Is a lazy loading singleton. </li></ul></ul><ul><ul><li>Gives the ability to determine the proper class to initialize at runtime. </li></ul></ul><ul><ul><li>This method is more elegant than reflection. </li></ul></ul><ul><ul><li>Reflection on the Dalvik VM is expensive. </li></ul></ul><ul><li>Let's look at a sample... </li></ul>
  10. 10. Holder Sample Code public abstract class PlayerNotification {     public static PlayerNotification getInstance() {         if (Integer.parseInt(Build.VERSION.SDK) <= 4)             return PreEclair.Holder.sInstance;         else             return EclairAndBeyond.Holder.sInstance;     }         public abstract void showNotification(Service context, int id, Notification notification);     public abstract void hideNotification(Service context, int id);     private static class PreEclair extends PlayerNotification {         ...     }     private static class EclairAndBeyond extends PlayerNotification {         ...     } }
  11. 11. What to do about resources? <ul><ul><li>Create graphics for each type of pixel density: </li></ul></ul><ul><ul><ul><li>hdpi - currently the Droid and Nexus One </li></ul></ul></ul><ul><ul><ul><li>mdpi - the most common pixel density type </li></ul></ul></ul><ul><ul><ul><li>ldpi - the tattoo, maybe more? </li></ul></ul></ul><ul><ul><li>  dip/dp - Device Independent Pixels. 1dp is equivalent to 1px at 160dpi. mdpi is approx. equivalent to 160 dpi. hdpi = 240 and ldpi 120. </li></ul></ul><ul><ul><li>Always extract strings from your source! Keeping strings in xml allows for easy localization! </li></ul></ul>
  12. 12. Some Android Best Practices.... <ul><ul><li>Documentation has certainly improved recently </li></ul></ul><ul><ul><li>&quot;premature optimization is the root of all evil.&quot; - Donald Knuth </li></ul></ul><ul><ul><li>Prefer Virtual over Interface... calling through an interface can take as much as 2x longer. </li></ul></ul><ul><ul><li>Use static methods if you aren't access the object's fields. </li></ul></ul><ul><ul><li>Use the enhanced for loop cautiously... ok for iterators .... not so good for ArrayLists. </li></ul></ul><ul><ul><li>Set private members to package level members when accessing from an inner class. </li></ul></ul>Knuth, Donald. Structured Programming with go to Statements.  Computing Surveys 6  (1974): 261–301
  13. 13. Some Numbers ..... Source:
  14. 14. Medialets Analytics SDK! <ul><ul><li>Reports application runs, durations, custom events, and uncaught exceptions </li></ul></ul><ul><ul><li>There's no cap on the amount of events that can be reported. </li></ul></ul><ul><ul><li>  See which versions of Android your users are running and on which devices. </li></ul></ul><ul><ul><li>Enable location services for your application events. </li></ul></ul><ul><ul><li>And its free! </li></ul></ul>
  15. 15. Questions!
  16. 16. <ul><li>Twitter/IRC </li></ul><ul><ul><li>michaelnovakjr </li></ul></ul>Blog: My Info...