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