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

From zero to a fully funcional and efficient An...

Quadbits
October 31, 2014

From zero to a fully funcional and efficient Android app

Charla en el GDG DevFest Android Granada (http://devfest.gdggranada.com/) el 31/10/2014. La charla cuenta nuestra experiencia desde que decidimos empezar a desarrollar aplicaciones para Android hasta que conseguimos terminar nuestra primera app completa con toda la funcionalidad y calidad que pretendíamos. Trataremos los problemas del desarrollo de apps, algunas maneras de solucionarlos y las fuentes de información y librerías de código abierto que conviene utilizar y seguir.

Quadbits

October 31, 2014
Tweet

Other Decks in Programming

Transcript

  1. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González Ignacio José García del Amo Quadbits SL Granada, Spain DevFest Android, October 2014, Granada, Spain http://www.quadbits.com [email protected], [email protected]
  2. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Contents 1 Introduction 2 The initial “by the book” approach 3 The path towards the final app 4 What to study / follow 5 Conclusions DevFest Android, October 2014, Granada, Spain 2 / 28
  3. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Contents 1 Introduction 2 The initial “by the book” approach 3 The path towards the final app 4 What to study / follow 5 Conclusions DevFest Android, October 2014, Granada, Spain 3 / 28
  4. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Who are we? Juan Ramón González González Founder, Android Development, Marketing and Gamification Ignacio José García del Amo Founder, Android Development, Backend and Design PhDs in Computer Science by the University of Granada The true value of a product, project, or solution → Be of good utility for a big number of people Jump into the entrepreneurial path! DevFest Android, October 2014, Granada, Spain 4 / 28
  5. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Self.migration() We started to learn about a lot of things: Startups Customer Development, Lean Startup https://www.udacity.com/course/ep245 Marketing, Gamification, Psychology Analytics (plus scientific method) → Proper metrics and analysis DevFest Android, October 2014, Granada, Spain 5 / 28
  6. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Self.migration() And we also needed to learn about. . . Android!. So we decided to start with a first app that included: UX: List, Map, Android Design Guidelines Internet access Backend Databases Background tasks Synchronization Plus. . . Being useful and interesting to do DevFest Android, October 2014, Granada, Spain 6 / 28
  7. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions The chosen app - Gasoline and Diesel Spain It allows you to find the cheapest filling stations around you or along a route Most processing is done on the Android device → Not that easy! DevFest Android, October 2014, Granada, Spain 7 / 28
  8. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Contents 1 Introduction 2 The initial “by the book” approach 3 The path towards the final app 4 What to study / follow 5 Conclusions DevFest Android, October 2014, Granada, Spain 8 / 28
  9. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions “The book” Reto Meier - Professional Android 4 Application Development ISBN 978-1118102275 - May 2012 Reto Meier, Dan Galpin, and Katherine Kuan - How To Develop Android Apps - Udacity - July 2014 https://www.udacity.com/course/ud853 Android developers site: https://developer.android.com/ https://developer.android.com/develop/index.html https://developer.android.com/design/index.html DevFest Android, October 2014, Granada, Spain 9 / 28
  10. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions The app “by the book” Platform JSON (DOM-like) → Lots of memory, very slow Switched to SAX / pull based implementations → Third parties Database (SQLite, content providers, db helpers, loaders, sync adapters,. . . ) → Lots of boilerplate and quite inefficient Implementing bulkInsert() helped, but it was not enough Compatible with Gingerbread and later → ActionBarSherlock → Android Support library v7 appcompat (More than 2 years later) So even at these first stages we needed to diverge from the standard implementations in several aspects Third party libraries can become the standard later on DevFest Android, October 2014, Granada, Spain 10 / 28
  11. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions The app “by the book” Examples and training code have errors Different bugs on different API levels → StackOverflow sometimes is not enough → Lots of debugging and hacking Compatible with Gingerbread and later → Create parallel implementations or use a lot of support / backport libraries All kinds of problems related to fragment and ListView → Animations, fast scrolling, lots of code branches for patching old API levels... and new API levels too → Bug fix injection? DevFest Android, October 2014, Granada, Spain 11 / 28
  12. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions The app “by the book” Testing is difficult and slow → Standard architecture is very tightly coupled, requires tests in device → Almost impossible to do proper TDD Robolectric helps, but it is always lagging → Platform changes and new features, build system changes, Android Studio, . . . Difficult to do unit tests instead of integration tests Android architecture “encourages” coding first and maybe do some tests later on DevFest Android, October 2014, Granada, Spain 12 / 28
  13. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Contents 1 Introduction 2 The initial “by the book” approach 3 The path towards the final app 4 What to study / follow 5 Conclusions DevFest Android, October 2014, Granada, Spain 13 / 28
  14. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Data design Removed platform database code Modelled filling station data as messages using Protobuf with custom optimized parser Alternatives → wire, flatbuffers, protostuff, Cap’n Proto, . . . Still including stub provider, authenticator, account, sync service, sync adapter, . . . → Just to download some data periodically! http://developer.android.com/training/ sync-adapters/creating-sync-adapter.html DevFest Android, October 2014, Granada, Spain 14 / 28
  15. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Protobuf Libraries.proto package android . l i b r a r i e s ; option java_package = "com. example . android . l i b r a r i e s " ; enum Category { Category1 = 0; Category2 = 1; Category3 = 2; } message Library { required uint32 id = 1; required s t r i n g name = 2; required s t r i n g u r l = 3; repeated Category category = 4 [ packed=true ] ; } protoc Libraries.proto → Generates code for Python and Java DevFest Android, October 2014, Granada, Spain 15 / 28
  16. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Backend The website of the Ministry was not reliable and fast enough Initial implementation using Drupal / php The data does not change “that fast” → Static photos of the data Final backend made in Python using TDD (unit, integration, and system tests) It also tries to fix problems with incomplete filling stations’ data Provides an optimized and compressed Protobuf feed to the app DevFest Android, October 2014, Granada, Spain 16 / 28
  17. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Updates Results as soon as possible → Caching, parallel downloads, . . . Reentrant update service → Connectivity and visibility changes, new data available, new user settings, . . . Fast cancelling of ongoing updates Only the last and proper results are propagated to the UI Parallelism and synchronization is hidden from update manager DevFest Android, October 2014, Granada, Spain 17 / 28
  18. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Location and other simple background tasks Inconsistent behavior in automatic location and geocoding Google Play Services is not always available / working properly Now uses platform / web APIs depending on device / status Still some issues → Reboot? → Most users won’t do it RxJava - Asynchronous and event-based composition for observable sequences https://github.com/ReactiveX/RxJava RxJava - Easier chaining of external API calls, transformations, threading and error handling → Highly recommended DevFest Android, October 2014, Granada, Spain 18 / 28
  19. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Contents 1 Introduction 2 The initial “by the book” approach 3 The path towards the final app 4 What to study / follow 5 Conclusions DevFest Android, October 2014, Granada, Spain 19 / 28
  20. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Sources of knowledge Android Weekly newsletter http://androidweekly.net/ Square - Jake Wharton - https://github.com/square/ Cyril Mottier - http://cyrilmottier.com/ Android Design in Action - YouTube The Android Arsenal - https://android-arsenal.com/ Android Development Community https://plus.google.com/communities/ 105153134372062985968 DevFest Android, October 2014, Granada, Spain 20 / 28
  21. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Open source libraries Dagger 2.0 https://github.com/google/dagger and http://square.github.io/dagger/ Reflection has a greater cost on mobile → Longer startup times Dagger 2.0 → Dependency injection with no reflection Injection errors are detected at compile time As fast as a manual implementation Can be used as a building block for testable architectures such as Model View Presenter (MVP), Clean Architecture → mortar, renderers, . . . DevFest Android, October 2014, Granada, Spain 21 / 28
  22. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Open source libraries RecyclerView Will be available on Android Support Library v21 (Android L) Designed as a more advanced and flexible version of ListView Uses a layout manager for positioning items Provides default animations for common item operations Efficient → View recycling, view holder pattern, . . . https://github.com/lucasr/twoway-view → More layout managers, item decorations, easier handling of clicks, . . . DevFest Android, October 2014, Granada, Spain 22 / 28
  23. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Open source libraries CardView Will be available on Android Support Library v21 (Android L) Show information inside cards that have a consistent look on any app Dynamic shadows and elevation (Material Design) Why Cards are the Future of the Web - Inside Intercom http://blog.intercom.io/ why-cards-are-the-future-of-the-web/ Examples: Google Play, Google Now, Twitter, Trello, Pinterest, . . . DevFest Android, October 2014, Granada, Spain 23 / 28
  24. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Open source libraries Glide https://github.com/bumptech/glide An image loading and caching library for Android focused on smooth scrolling Media decoding, memory and disk caching, and resource pooling Fluent API, transformations, bitmap reuse, . . . Alternatives: Picasso (http://square.github.io/picasso/), ion (https://github.com/koush/ion), . . . DevFest Android, October 2014, Granada, Spain 24 / 28
  25. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Open source libraries Realm http://realm.io/ Designed as a mobile database: a replacement for SQLite (Android) & Core Data (iOS) Backed by Y Combinator Zynga hired Realm back in 2012 to build a database that allowed it to shut down a number of its cloud clusters May be a better/easier alternative than protobuf in many cases See also: greenDao (http://greendao-orm.com/), OrmLite (http://ormlite.com/), . . . DevFest Android, October 2014, Granada, Spain 25 / 28
  26. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Contents 1 Introduction 2 The initial “by the book” approach 3 The path towards the final app 4 What to study / follow 5 Conclusions DevFest Android, October 2014, Granada, Spain 26 / 28
  27. Quadbits From zero to a fully funcional and efficient Android

    app Juan Ramón González González, Ignacio José García del Amo Introduction The initial “by the book” approach The path towards the final app What to study / follow Conclusions Conclusions You need months of preparation and learning before you can tackle an important app development So... don’t start a company too soon Don’t follow a single source of truth in how to do things Keep a look on what others are doing and follow the best ones If you act clever and work hard... Impossible things can happen :) DevFest Android, October 2014, Granada, Spain 27 / 28
  28. Quadbits Thanks for your attention! Juan Ramón González González Ignacio

    José García del Amo Quadbits SL Granada, Spain http://www.quadbits.com [email protected], [email protected]