Upload
trey-robinson
View
4.221
Download
0
Embed Size (px)
Citation preview
10 Commandments for Better Android Development
Trey Robinson
Thou shalt pick a reasonable min sdk version. (9 is not reasonable)
(14 isn’t either)
Choosing a Min SDK
Choosing a Min SDK
● Froyo + Gingerbread + ICS = 8.7%● Users with older OS versions download
fewer applications. ● Newer features and better phones often
mean faster time to market with a better product.
So my Min SDK should be….
19(Seriously)
(If you must go lower.. 16)
Thou shalt not write boilerplate code.(Ain’t nobody got time for that)
● View inflation● OnClick, OnItemSelected.. etc etc● Saving state ● Parcelables
Things you should understand..
Never write them again...Old WayNew Way
And OnClicks...
Icepick and Saving State..
Parcelables
Automatic Parcelables
● Parcelable Plugin○ https://github.com/mcharmas/android-parcelable-intellij-plugin
● Auto Parcel○ https://github.com/frankiesardo/auto-parcel
● Parceler○ https://github.com/johncarl81/parceler
Know thy IDEYou companion on the path to speed and
agility
● Control + R● Control + D● ⌘ + Shift + O● ⌘ + Shift + Up/Down● ⌘ + Option + Up/Down● ⌘ + Shift + f
Useful Hotkeys
Live Templates(Demo)
https://github.com/keyboardsurfer/idea-live-templates
MORE LIVE TEMPLATES
Thou shalt not consume REST APIs with AsyncTasks
(Unless you are a masochist)
Retrofit vs Volley vs AsyncTask
Thou shalt read Effective Java.
Some useful stuff..● Factory vs Constructors● Builders● Singletons● equals and hashCode● toString● Class accessibility● Mutability● Composition vs Inheritance● Interfaces vs Abstract Classes● Generics● Lists vs Arrays● Enum vs int constants● Overloading● Javadoc● loops● String concatenation● Exceptions● Concurrency
Thou shalt not ask permission when an Intent will do.
(or how to avoid upsetting your users)
<uses-permission android:name="android.permission.SEND_SMS" />
Example: Sending an SMSOption One:
Option Two:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:" + telephoneNumber));
sendIntent.putExtra("sms_body", x);
startActivity(sendIntent);
Thou shalt understand your builds.
(and make them faster and more useful)
● Manifest Mergers● A little bit of Groovy● Sweet debug settings
Things to Learn
For example..
<application android:vmSafeMode="true">
Added to the manifest in debug/src/AndroidManifest.xml
Environment VariablesbuildTypes { debug { buildConfigField "String", "BASE_URL", "\"https://myserver-dev.herokuapp.com\";" } qa { buildConfigField "String", "BASE_URL", "\"https://myserver-qa.herokuapp.com\";" signingConfig signingConfigs.debug } support { buildConfigField "String", "BASE_URL", "\"https://myserver-support.herokuapp.com\";" signingConfig signingConfigs.debug } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt' buildConfigField "String", "BASE_URL", "\"https://www.myserver.com\";" }
}
(a what?)
Thou shalt use an activity alias for your launcher
<activity android:name=".Launcher" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter></activity>
Like so..<activity-alias android:name=".Launcher" android:targetActivity=".ui.MyNewLauncher" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter></activity-alias>
<activity android:name=".ui.MyNewLauncher" />
Thou shalt stand on the shoulders of giants.
(Or how to increase your knowledge in 3 easy steps.)
1. Attend meetups! (DONE)2. Leverage cool libraries and techniques for
fun and profit.3. Follow people on twitter.
So Easy...
Cool Libraries
● RXJava● Dagger / Dagger 2● Picasso / Universal Image Loader / Glide● Design Support Library● Pocket Knife● Realm● Stetho
Twitter Follows
● Jake Wharton @JakeWharton● Dan Lew @danlew42● Chet Haase @chethaase● And many many many more...https://twitter.com/rdrobinson3/lists/android
THE END