Android best practices 2015

  • View
    9.727

  • Download
    5

  • Category

    Software

Preview:

Citation preview

© 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

© 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

© 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

© Sean Katz

Tips on learning Tipz - browse tipz.io

6

© Sean Katz

Tips on learning Tipz - browse commits

7

© Sean Katz

Tips on learning Tipz - blame a file

8

© Sean Katz

Tips on learning Tipz - browse pull reqs

9

© Sean Katz

Tips on learning Tipz - continuously learn

10

© Sean Katz

Contributors gets backstage access

11

© Sean Katz

FULL BLOWN ARCHITECTURE

Weeks of programming can save you hours of planning

12

© Sean Katz

What is an Android app?

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

13

© Sean Katz

PLAN ARCHITECTURE

ACTIVITY (or FRAGMENT)

ViewableInteractionsForeground

SERVICE

EngineBlackBoxBackgroundNetwork

Go Fetch content

Broadcast status

CONTENTPROVIDER

DataURIsEncapsulation

Results? Data CRUD

Sync

14

© Sean Katz

GRADLE

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

- Donald Knuth

15

© Sean Katz

Hello: GRADLE

● Build system○ Like Grunt○ Forget ‘Ant’

● Groovy● Terminal run

16

© 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

© Sean Katz

GIT

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

- Henry Ford

21

© Sean Katz

Hello: GIT

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

22

© Sean Katz

Hello: GIT flow

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

24

© 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

© Sean Katz

“By failing to prepare, you are preparing to fail

ANDROID APIs & SUPPORT LIBRARY

- Benjamin Franklin

29

© 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

© 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

© Sean Katz

❤ SUPPORT LIBRARY - standalonesCorresponding Features from support API level

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

Standalone

© Sean Katz

“Simplicity is the ultimate form of sophistication

APP CODE SKELETONS

- Leonardo da Vinci

34

© 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

© Sean Katz

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

BOILERPLATE CODE

- Bill Gates

40

© 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

© Sean Katz

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

PERFORMANCE

- Craig Bruce

43

© 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

© Sean Katz

GPU Overdraw

47

No color 0X

Blue 1X

Green 2X

Light Red 3X

Dark Red 4X +

© Sean Katz

Profile GPU Rendering

48

Blue Draw (Java)

Red Process (Render)

Orange Execute (Pipeline)

Green 60 FPS target

© Sean Katz

Show Layout Bounds (Developer tools)

50

© Sean Katz

Show Layout Bounds (Android Device Monitor)

51

© Sean Katz

Network Statistics

52

Tag network using:android.net.TrafficStats

© Sean Katz

System Information

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

55

© 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

© Sean Katz

Hello: CI

● Automation○ Trigger○ Build○ Test○ Deploy

● Tools○ Jenkins○ ship.io (SaaS)

57

© 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

© 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

© Sean Katz

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

GRAPHICAL DESIGN

- Ken Olson, 1977

63

© Sean Katz

Android Design Cheat-Sheet

64

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

© 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

© Sean Katz

THANKS!Any questions?

68blog.android-develop.com

@_SeanKatz

sean.katz@gmail.com

www.linkedin.com/in/seankatz

© 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

Recommended