Upgrade to Pro — share decks privately, control downloads, hide ads and more …

10 Common mistakes that Android Developers do

10 Common mistakes that Android Developers do

The second day keynote from DroidCon Zagreb 2016. http://droidcon.hr/en/sessions/10-common-mistakes-android-developers-do

Erik Hellman

April 29, 2016
Tweet

More Decks by Erik Hellman

Other Decks in Programming

Transcript

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

    View full-size slide

  2. 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

    View full-size slide

  3. 1. People are different

    View full-size slide

  4. Accessability (a11y)

    View full-size slide

  5. Accessibility in Action
    Kelly Shuster, DroidCon Berlin 2015

    View full-size slide

  6. Different form factors

    View full-size slide

  7. Stop doing this!
    android:name=".ActivitySplash"
    android:screenOrientation="portrait">





    View full-size slide

  8. 2. Cross-platform
    assumptions

    View full-size slide

  9. Cross-platform tools

    View full-size slide

  10. Your first options

    View full-size slide

  11. 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);
    });
    }

    View full-size slide

  12. 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;

    View full-size slide

  13. 3. Very long builds

    View full-size slide

  14. ./gradle clean assembleDebug --profile

    View full-size slide

  15. Don't forget the lead
    times of your PRs!

    View full-size slide

  16. 4. Testing strategy

    View full-size slide

  17. Too much or
    not at all?

    View full-size slide

  18. Automate all the things!

    View full-size slide

  19. 5. Leaking contexts

    View full-size slide

  20. 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)

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  24. 6. Security mistakes

    View full-size slide

  25. 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"
    }
    }

    View full-size slide

  26. 7. Picking the right library!

    View full-size slide

  27. Emerging and Disruptive

    View full-size slide

  28. 8. API Level

    View full-size slide

  29. Official stats (April 2016)

    View full-size slide

  30. Android versions 2015

    View full-size slide

  31. Exepctations vs Reality

    View full-size slide

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

    View full-size slide

  33. 9. Get an iPhone!

    View full-size slide

  34. 10. Sharing is caring

    View full-size slide

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

    View full-size slide