Architectural Components
Architectural, UI & Think Components
Design of Mobile
Starting with the basics of writing clean code (SOLID, Rx, TDD & DI with Kotlin)
Applying Material Design U&I with the latest research we build intuitive UX (engage & retain) and responsive UI (optimistic rendering).
Design Thinking uses iterative data driven ethnography to build empathy and solve major pain points, ensuring we are build the correct product.
https://academy.realm.io/posts/droidcon-boston-siamak-ashrafi-real-world-android-native-development/
We have good base … not a framework!
App components
App components are the essential building blocks of an Android app ??? NO !!!
The Problem
"How should I design my Android application? What kind of MVC pattern should I use? What should I use for an event bus?" “
It is probably better to call the core Android APIs a ‘system framework.’ For the most part, the platform APIs we provide are there to define how an application interacts with the operating system; but for anything going on purely within the app, these APIs are often just not relevant.” - Dianne Hackborn
Problem Resolution → Solution
Android Architecture Components work together to implement a sane app architecture, while they individually address developer pain points.
Pieces needed to finish the platform:
Fixing Android UIssues
What Happened? & Why Important?
First time the Android Team is proposing an architecture for Android.
This is a significant shift from the past where The Android Team did not give any direction or advice on how to structure an Android App.
Android UI Team add a constraint library
UI can handle different screen sizes and rotation
First time the Android Team is supporting a new language.
Although this language is compatible with java it is far better because it started with baking in Effective Java (JDK9)
Android Material Design released Material Components
UI components built with “best practice”
Android Architecture Components
https://developer.android.com/topic/libraries/architecture/guide.html
Lifecycle Aware Components
Android Activity LifeCycle / Fragment LifeCycle
AsyncTask
AsyncTask (API Level 3) allows you to perform asynchronous work on your user interface. It performs the blocking operations in a worker thread and then publishes the results on the UI thread, without requiring you to handle threads and/or handlers yourself.
Rotate Phone
AsyncTaskLoader & CursorLoader (DB)
AsyncTaskLoader(API Level 11) & CursorLoader
Loaders solve these problems and includes other benefits. For example:
Making loading data lifecycle aware (2/3/2016)
Handling Lifecycles
The android.arch.lifecycle package provides classes and interfaces that let you build lifecycle-aware components — which are components that can automatically adjust their behavior based on the current lifecycle of an activity or fragment.
Lifecycle Aware Data Loading with Architecture Components(5/17/2017)
Lifecycle Owner
LifecycleOwner is a single method interface that denotes that the class has a Lifecycle. It has one method, getLifecycle(), which must be implemented by the class.
Lifecycle [Activity / Fragment]
Lifecycle is a class that holds the information about the lifecycle state of a component (like an activity or a fragment) and allows other objects to observe this state.
Lifecycle Observer
Class My<Function>Listener implements LifecycleObserver
@OnLifecycleEvent(Lifecycle.Event.ON_START)
void start() { if (enabled) { // connect }}
https://developer.android.com/reference/android/arch/lifecycle/Lifecycle.Event.html
ON_CREATE, ON_START, ON_RESUME, ON_PAUSE, ON_STOP, ON_DISTROYED, ON_ANY ...
if (lifecycle.getState().isAtLeast(STARTED)) {
// connect if not connected }
Events & States
LifeCycles (Activity & Fragments)
Lifecycle is a class that holds the information about the lifecycle state
LiveData
LiveData Flow
LiveData
public class typeLiveData extends LiveData<type> { @Override ...
onActive() - This method is called when the LiveData has an active observer. This means we need to start observing the updates.
onInactive() -This method is called when the LiveData does not have any active observers. This is important because staying connected consumes significant battery power without any benefit.
setValue() - Calling this method updates the value of the LiveData instance and notifies active observers about the change.
Using LiveData
Transformations of LiveData
Provides a Transformations class that includes helper methods for these operations.
Applies the given function on the main thread to each value emitted by source LiveData and returns LiveData, which emits resulting values.
Creates a LiveData, let's name it swLiveData, which follows next flow: it reacts on changes of trigger LiveData, applies the given function to new value of trigger LiveData and sets resulting LiveData as a "backing" LiveData to swLiveData. "Backing" LiveData means, that all events emitted by it will retransmitted by swLiveData.
Advantages of LiveData
LiveData is a data holder class that keeps a value and is observed.
ViewModel
ViewModel
Provide data for UI components and survive config change
ViewModel
ViewModel InAction
Sharing Data Between Fragments
Room Persistence Library
Room Persistence Library
Entity
When a class is annotated with @Entity and is referenced in the entities property of a @Database annotation, Room creates a database table for that entity in the database.
DAO
DAOs abstract access to the database in a clean way (normal SQL).
(CRUD)
@Insert
@Query
@Update
@Delete
Database
You can use this component to create a database holder. The annotation defines the list of entities, and the class's content defines the list of data access objects (DAOs) in the database.
ROOM Layout
Android App Architecture
Arch Guiding principles
Arch Guiding principles
Architectural components
Architecture
Final Reference Architecture
Firestore UI
LiveData
Building the user interface
Handles the communication with the business part of data handling & is not affected by configuration changes such as recreating an activity due to rotation.
It lets the components in your app observe LiveData objects for changes without creating explicit and rigid dependency paths between them.
Mediators between different data sources (persistent model, web service, cache, etc.)
Constraint Library
Android Material components
CodeLabs & GitHub.
This codelab introduces you to lifecycle-aware architecture components for building Android apps. CodeLab
The new Room Persistence Library guarantee SQL statements at compile-time and removes boilerplate code related to storing data locally in SQLite CodeLab
Github:
BasicSample - Shows how to persist data using a SQLite database and Room. Also uses ViewModels and LiveData.
PersistenceContentProviderSample - Shows how to expose data via a Content Provider using Room.
GithubBrowserSample - An advanced sample that uses the Architecture components, Dagger and the Github API. Requires Android Studio 3.0 canary 1
TDD
Android UI Instrumentation test.Espresso test.
The ViewModel can be tested using a JUnit test.
You can test the UserRepository with a JUnit test as well.
Using instrumentation tests with in-memory database
Kotlin
Kotlin fixes a series of issues that Java suffers from
Think With Google
Analytics and data is essential to developing, optimising and marketing apps in the best possible ways to increase users, reach and return on investment. The best apps in the world are constantly checked and analysed by their creators, fine tuned to reach the right audience, to improve their experience and to bring them the content or the services they want.
http://appindex.com/blog/big-list-app-analytics-tools/
Google:
https://developers.google.com/analytics/
Secrets to App Success on Google Play (A / B Testing)
Google Marketing Research & Digital Trends https://www.thinkwithgoogle.com/
*In God we trust … Everyone else bring DATA!
Think with Google
Leaning “Think With Google” to Design
Non Google Play Distribution
Google Play Store* (Developers Page)
https://developer.android.com/google/play/dist.html (use staged rollouts)
*Understanding Statistically Valid Performance