Slide 1

Slide 1 text

10 Common mistakes that Android developers do Erik Hellman @ErikHellman - www.hellso!.se

Slide 2

Slide 2 text

Erik Hellman Freelance So!ware Developer Stockholm, Sweden Previously Ericsson, Sony Mobile, Spotify (and more) Drinks most coffee Author of Android Programming - Pushing the Limits

Slide 3

Slide 3 text

Slide 4

Slide 4 text

1. People are different

Slide 5

Slide 5 text

Accessability (a11y)

Slide 6

Slide 6 text

Accessibility in Action Kelly Shuster, DroidCon Berlin 2015

Slide 7

Slide 7 text

Different form factors

Slide 8

Slide 8 text

Stop doing this!

Slide 9

Slide 9 text

2. Cross-platform assumptions

Slide 10

Slide 10 text

Cross-platform tools

Slide 11

Slide 11 text

Your first options

Slide 12

Slide 12 text

HTML5 Service Worker if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js') .then(function(registration) { // Registration was successful console.log('ServiceWorker registration successful!'); }) .catch(function(err) { // registration failed :( console.log('ServiceWorker registration failed: ', err); }); }

Slide 13

Slide 13 text

Modern C++ // auto std::vector container = // fetch container... for (auto it = container.begin(); it != it.end(); it++) { // type of it is std::vector::iterator } // lambdas auto is_odd = [](int n) {return n%2==1;}; // Strongly typed enums enum class Options {None, One, All}; Options o = Options::All;

Slide 14

Slide 14 text

3. Very long builds

Slide 15

Slide 15 text

./gradle clean assembleDebug --profile

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Don't forget the lead times of your PRs!

Slide 18

Slide 18 text

4. Testing strategy

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Too much or not at all?

Slide 21

Slide 21 text

Automate all the things!

Slide 22

Slide 22 text

5. Leaking contexts

Slide 23

Slide 23 text

Looks familar? E/AndroidRuntime(379): FATAL EXCEPTION: main E/AndroidRuntime(379): java.lang.IllegalStateException: Activity has been destroyed E/AndroidRuntime(379): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1365) E/AndroidRuntime(379): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595) E/AndroidRuntime(379): at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:578) E/AndroidRuntime(379): at com.app.main.AppMainTabActivity.pushFragments(AppMainTabActivity.java:650) E/AndroidRuntime(379): at com.app.home.Home$ExpandableListAdapter$1.onClick(Home.java:530) E/AndroidRuntime(379): at android.view.View.performClick(View.java:2408) E/AndroidRuntime(379): at android.view.View$PerformClick.run(View.java:8816) E/AndroidRuntime(379): at android.os.Handler.handleCallback(Handler.java:587) E/AndroidRuntime(379): at android.os.Handler.dispatchMessage(Handler.java:92) E/AndroidRuntime(379): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime(379): at android.app.ActivityThread.main(ActivityThread.java:4627) E/AndroidRuntime(379): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(379): at java.lang.reflect.Method.invoke(Method.java:521) E/AndroidRuntime(379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) E/AndroidRuntime(379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) E/AndroidRuntime(379): at dalvik.system.NativeStart.main(Native Method)

Slide 24

Slide 24 text

– What do we want? – Now! – When do we want it? – Fewer race conditions! — Developers

Slide 25

Slide 25 text

Leak Canary https://github.com/square/leakcanary

Slide 26

Slide 26 text

@WorkerThread public void doNetworkStuff() { // Do network stuff here... } @MainThread public void doUiStuff() { // Update the UI here }

Slide 27

Slide 27 text

6. Security mistakes

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

signingConfigs { release { storeFile file("./cert/release_keystore.jks") storePassword S3cr3tP4ssw0rd keyAlias android keyPassword S3cr3tP4ssw0rd } debug { storeFile file("./cert/debug_keystore.jks") storePassword "appdebug" keyAlias "debug" keyPassword "appdebug" } }

Slide 30

Slide 30 text

7. Picking the right library!

Slide 31

Slide 31 text

Emerging and Disruptive

Slide 32

Slide 32 text

8. API Level

Slide 33

Slide 33 text

Official stats (April 2016)

Slide 34

Slide 34 text

Android versions 2015

Slide 35

Slide 35 text

Exepctations vs Reality

Slide 36

Slide 36 text

· Track actual usage · Perform user studies in public · Play Store keeps old versions available

Slide 37

Slide 37 text

9. Get an iPhone!

Slide 38

Slide 38 text

10. Sharing is caring

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Thank you for listening! @ErikHellman - www.hellsoft.se