69
© Sean Katz Best ANDROID Development Practices 1

Android best practices 2015

Embed Size (px)

Citation preview

Page 2: Android best practices 2015

© Sean Katz

Hello!I AM SEAN KATZ

I love (Android) developmentHope you’ll love it too.

- Software Dev Manager @ Autodesk- Previously Co-Founder @ for-each- 10 Years work in software dev- Passionate about Mobile & Web- Father of Mini

2

Page 3: Android best practices 2015

© Sean Katz

SUBJECTS TODAY

1. Architecture2. Gradle3. Android Studio4. Git5. Manifest6. APIs & Support Lib7. App Code Skeletons

1. Boilerplate code2. Performance3. Debug & Measure4. CI5. Security6. Graphical Design

3

Page 4: Android best practices 2015

© Sean Katz

What is Tipz.io ?

○ 2 in 1:● Bite-Size Tips platform for acquiring skills● Open Source Initiative for educational purposes

○ Contribute! Web, Android & iOS dev, DevOps, UX/UI work,

marketing, branding, SEO… show your skills on tipz!

○ Earn endless love & real-life reputation

4

Page 6: Android best practices 2015

© Sean Katz

Tips on learning Tipz - browse tipz.io

6

Page 7: Android best practices 2015

© Sean Katz

Tips on learning Tipz - browse commits

7

Page 8: Android best practices 2015

© Sean Katz

Tips on learning Tipz - blame a file

8

Page 9: Android best practices 2015

© Sean Katz

Tips on learning Tipz - browse pull reqs

9

Page 10: Android best practices 2015

© Sean Katz

Tips on learning Tipz - continuously learn

10

Page 11: Android best practices 2015

© Sean Katz

Contributors gets backstage access

11

Page 12: Android best practices 2015

© Sean Katz

FULL BLOWN ARCHITECTURE

Weeks of programming can save you hours of planning

12

Page 13: Android best practices 2015

© Sean Katz

What is an Android app?

Choose one or more:✓ Activity - display❏ Service - do❏ Content Provider - data❏ Broadcast - communicate

13

Page 14: Android best practices 2015

© Sean Katz

PLAN ARCHITECTURE

ACTIVITY (or FRAGMENT)

ViewableInteractionsForeground

SERVICE

EngineBlackBoxBackgroundNetwork

Go Fetch content

Broadcast status

CONTENTPROVIDER

DataURIsEncapsulation

Results? Data CRUD

Sync

14

Page 15: Android best practices 2015

© Sean Katz

GRADLE

Computers are good at following instructions, but not at reading your mind

- Donald Knuth

15

Page 16: Android best practices 2015

© Sean Katz

Hello: GRADLE

● Build system○ Like Grunt○ Forget ‘Ant’

● Groovy● Terminal run

16

Page 18: Android best practices 2015

© Sean Katz

ANDROID STUDIO

My favorite things in life don't cost any money. It's really clear that the most precious resource we all have is time

- Steve Jobs

18

Page 21: Android best practices 2015

© Sean Katz

GIT

Coming together is a beginning. Keeping together is progress. Working together is success

- Henry Ford

21

Page 22: Android best practices 2015

© Sean Katz

Hello: GIT

● Popular SCM● Branch away● Collaborate● Code Review● Open Source

22

Page 24: Android best practices 2015

© Sean Katz

Hello: GIT flow

● Master● Develop● Feature/*● Release/*● Hotfix/*

24

Page 26: Android best practices 2015

© Sean Katz

“The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had

MANIFEST

- Eric Schmidt

26

Page 29: Android best practices 2015

© Sean Katz

“By failing to prepare, you are preparing to fail

ANDROID APIs & SUPPORT LIBRARY

- Benjamin Franklin

29

Page 30: Android best practices 2015

© Sean Katz

ANDROID APIsCode name Version API level

Lollipop 5.0 21

KitKat 4.4.x 19

Jelly Bean 4.1.x, 4.2.x, 4.3.x 16 - 18

Ice Cream Sandwich 4.0.3, 4.0.4 15

Ice Cream Sandwich 4.0.1, 4.0.2 14

Honeycomb 3.x 11-13

Froyo, Gingerbread 2.2.x - 2.3.x 8-10

Cupcake, Donut, Eclair 1.x - 2.1.x 1-7

Minimum API

< ~8% users

Target APICompiled SDK

30

Page 31: Android best practices 2015

© Sean Katz

❤ SUPPORT LIBRARYCorresponding Features from support API level

● getExternalStorageState● Notification (additions - wear, car, ...)

21

● ConnectivityManager● Notification (additions)● Nested Fragments (v4) (issue)

16 - 18

● Fragment● ActionBar, ActionBarDrawerToggle● Material design, Toolbar● ViewPager, FragmentPagerAdapter● LocalBroadcastManager● Loader● Share, ShareActionProvider● SearchView● GridLayout

14

11-13

8-10

1-7

Minimum API

< ~8% users

Target APICompiled SDK

31

Page 32: Android best practices 2015

© Sean Katz

❤ SUPPORT LIBRARY - standalonesCorresponding Features from support API level

● DrawerLayout● SlidingPaneLayout● PrintHelper● SwipeRefreshLayout ● CardView● RecyclerView● Palette● Multidex

Standalone

Page 34: Android best practices 2015

© Sean Katz

“Simplicity is the ultimate form of sophistication

APP CODE SKELETONS

- Leonardo da Vinci

34

Page 38: Android best practices 2015

© Sean Katz

SHARED PREFS Tipz

https://github.com/tipz/tipz-android/pull/1/1. Shared Preference commit() is not the

only option2. Smartly organized SharedPreferences3. Do not store secrets in the Shared

Preferences (+ encryption example)

38

Page 40: Android best practices 2015

© Sean Katz

“Measuring programming progress by lines of code is like measuring aircraft building progress by weight

BOILERPLATE CODE

- Bill Gates

40

Page 41: Android best practices 2015

© Sean Katz

Hello: BOILERPLATE CODE○ BaseFragment - tag, debug, inflate

○ BaseLoadingFragment - progress views○ BaseDataFragment - connects to data

○ BaseDataAdapterFragment - w/ adapter○ BaseDataAdapterPagingFragment

○ Service○ IntentService - off-the-ui-thread, queue

○ WakefulIntentService - stays awake○ BaseService - broadcasts, access ease

○ ContentService - provider, REST api’s

41

Page 43: Android best practices 2015

© Sean Katz

“It's hardware that makes a machine fast. It's software that makes a fast machine slow

PERFORMANCE

- Craig Bruce

43

Page 45: Android best practices 2015

© Sean Katz

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

DEBUG & MEASURE TOOLS

- Brian Kernighan

45

Page 47: Android best practices 2015

© Sean Katz

GPU Overdraw

47

No color 0X

Blue 1X

Green 2X

Light Red 3X

Dark Red 4X +

Page 48: Android best practices 2015

© Sean Katz

Profile GPU Rendering

48

Blue Draw (Java)

Red Process (Render)

Orange Execute (Pipeline)

Green 60 FPS target

Page 50: Android best practices 2015

© Sean Katz

Show Layout Bounds (Developer tools)

50

Page 51: Android best practices 2015

© Sean Katz

Show Layout Bounds (Android Device Monitor)

51

Page 52: Android best practices 2015

© Sean Katz

Network Statistics

52

Tag network using:android.net.TrafficStats

Page 55: Android best practices 2015

© Sean Katz

System Information

1. Activity Manager State2. Package Information3. Memory Usage4. Memory use over time5. Graphics State

55

Page 56: Android best practices 2015

© Sean Katz

“An iPod, a phone, an internet mobilecommunicator... these are NOT three separatedevices! And we are calling it iPhone! Today Apple is going to reinvent the phone

Continuous Integration

- Steve Jobs56

Page 57: Android best practices 2015

© Sean Katz

Hello: CI

● Automation○ Trigger○ Build○ Test○ Deploy

● Tools○ Jenkins○ ship.io (SaaS)

57

Page 59: Android best practices 2015

© Sean Katz

“The only truly secure system is one that is powered off, cast in a block of concrete and sealed in a lead-lined room with armed guards

SECURITY

– Gene Spafford

59

Page 62: Android best practices 2015

© Sean Katz

REVERSE ENGINEERING Tipz

1. Reverse own app for security checkup2. Steps:

a. Rename app.APK to app.ZIPb. extract app.ZIPc. classes.dex -> jar (tool)

3. Output:a. Java files: jar -> clear text java (tool)b. Resources: Folder “res” with the resources

62

Page 63: Android best practices 2015

© Sean Katz

“There is no reason anyone would want acomputer in their home

GRAPHICAL DESIGN

- Ken Olson, 1977

63

Page 64: Android best practices 2015

© Sean Katz

Android Design Cheat-Sheet

64

http://possiblemobile.com/wp-content/uploads/2014/01/Android-Design-Cheat-Sheet-highres.png

Page 65: Android best practices 2015

© Sean Katz

PRODUCTIVE TEAMWORK

1. Productive Teamwork Blog Post ☞a. Understanding the different configurationsb. Planning a dynamic layoutc. Real estate of the screend. Stretching techniques (9 patch)e. Full screen imagesf. Folder and Files naming conventionsg. Marketing (Google Play) assets

65

Page 68: Android best practices 2015

© Sean Katz

THANKS!Any questions?

68blog.android-develop.com

@_SeanKatz

[email protected]

www.linkedin.com/in/seankatz

Page 69: Android best practices 2015

© Sean Katz

Line Icons by Webalys, Virgil Pana and Mirko Monti are published under a Creative Commons Attribution license and Free for both personal and commercial use. You can copy, adapt, remix, distribute or transmit them. If you use these sets on your presentation remember to keep the “Credits” slide or provide a mention and link to these resources:

● Mirko Monti - Simple line icons● Virgil Pana - E-commerce icons● Webalys - Streamline iconset 69

ASSETS CREDITS