33
10 Commandments for Better Android Development Trey Robinson

10 commandments for better android development

Embed Size (px)

Citation preview

Page 1: 10 commandments for better android development

10 Commandments for Better Android Development

Trey Robinson

Page 2: 10 commandments for better android development

Thou shalt pick a reasonable min sdk version. (9 is not reasonable)

(14 isn’t either)

Page 3: 10 commandments for better android development

Choosing a Min SDK

Page 4: 10 commandments for better android development

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.

Page 5: 10 commandments for better android development

So my Min SDK should be….

19(Seriously)

(If you must go lower.. 16)

Page 6: 10 commandments for better android development

Thou shalt not write boilerplate code.(Ain’t nobody got time for that)

Page 7: 10 commandments for better android development

● View inflation● OnClick, OnItemSelected.. etc etc● Saving state ● Parcelables

Things you should understand..

Page 8: 10 commandments for better android development

Never write them again...Old WayNew Way

Page 9: 10 commandments for better android development

And OnClicks...

Page 10: 10 commandments for better android development

Icepick and Saving State..

Page 11: 10 commandments for better android development

Parcelables

Page 12: 10 commandments for better android development

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

Page 13: 10 commandments for better android development

Know thy IDEYou companion on the path to speed and

agility

Page 14: 10 commandments for better android development

● Control + R● Control + D● ⌘ + Shift + O● ⌘ + Shift + Up/Down● ⌘ + Option + Up/Down● ⌘ + Shift + f

Useful Hotkeys

Page 15: 10 commandments for better android development

Live Templates(Demo)

Page 16: 10 commandments for better android development

https://github.com/keyboardsurfer/idea-live-templates

MORE LIVE TEMPLATES

Page 17: 10 commandments for better android development

Thou shalt not consume REST APIs with AsyncTasks

(Unless you are a masochist)

Page 18: 10 commandments for better android development

Retrofit vs Volley vs AsyncTask

Page 19: 10 commandments for better android development

Thou shalt read Effective Java.

Page 20: 10 commandments for better android development

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

Page 21: 10 commandments for better android development

Thou shalt not ask permission when an Intent will do.

(or how to avoid upsetting your users)

Page 22: 10 commandments for better android development

<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);

Page 23: 10 commandments for better android development

Thou shalt understand your builds.

(and make them faster and more useful)

Page 24: 10 commandments for better android development

● Manifest Mergers● A little bit of Groovy● Sweet debug settings

Things to Learn

Page 25: 10 commandments for better android development

For example..

<application android:vmSafeMode="true">

Added to the manifest in debug/src/AndroidManifest.xml

Page 26: 10 commandments for better android development

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\";" }

}

Page 27: 10 commandments for better android development

(a what?)

Thou shalt use an activity alias for your launcher

Page 28: 10 commandments for better android development

<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" />

Page 29: 10 commandments for better android development

Thou shalt stand on the shoulders of giants.

(Or how to increase your knowledge in 3 easy steps.)

Page 30: 10 commandments for better android development

1. Attend meetups! (DONE)2. Leverage cool libraries and techniques for

fun and profit.3. Follow people on twitter.

So Easy...

Page 31: 10 commandments for better android development

Cool Libraries

● RXJava● Dagger / Dagger 2● Picasso / Universal Image Loader / Glide● Design Support Library● Pocket Knife● Realm● Stetho

Page 32: 10 commandments for better android development

Twitter Follows

● Jake Wharton @JakeWharton● Dan Lew @danlew42● Chet Haase @chethaase● And many many many more...https://twitter.com/rdrobinson3/lists/android

Page 33: 10 commandments for better android development

THE END