Modern Android App Architecture with JetPack and Dropbox Store

0
21

Dropbox recently took ownership of the open-source Store library to revamp it and bring it closer to the current Android developer ecosystem. Originally developed at the New York Times, Store has been rewritten in Kotlin on the foundations provided by Coroutines and Flow. Along with Google JetPack collection of libraries, Dropbox Store provides a solution to create modern Android apps.

When Google introduced JetPack, it set an ambitious goal for it: accelerating development of high-quality apps for the Android platform. Two key ideas drove the design of JetPack towards that goal. On the one hand, JetPack aims to leverage advanced Kotlin features to reduce boilerplate code programmers had to write. On the other hand, it also provides higher-level abstractions on top of those found in the Android SDK, such as Fragments and [Activities](https://developer.android.com/guide/components/activities/intro-activities), to allow them to express complex tasks in a simpler way.

JetPack includes a number of components that can be used independently on one another and cover four main concern areas: Foundation, Architecture, Behavior, and User Interface, as shown in the following image.

Along with JetPack, Google published its own recommended Android app architecture, which defines what modules usually make an Android app and how they interact with each other. The fundamental tenets of a well-architected Android app are separation of concerns, model-driven UI, and one-directional dependencies across modules, as exemplified in the following image.

JetPack provides most of the components to create an Android app following Google suggested architecture, with the exception of the Repository layer. As Store creator Mike Nakhimovich writes,

Repository currently only has a few code samples and no reusable abstractions that work across different implementations. That’s one of the big reasons why Dropbox is investing in Store–to solve this gap in the architecture model above.

By relying on a reactive design, Store aims to support the creation of Android apps where data flows in and out of the UI in a seamless way that does not force the user to navigate back and forth or otherwise explicitly request it to be updated.

Reactive front ends led me to think of how we can have declarative data stores with simple APIs that abstract complex features like multi-request throttling and disk caching that are needed in modern mobile applications.

Briefly, Dropbox Store enables connecting the app model with an external data source using a declarative interface that centralizes all data-related operations. It strives to optimize network usage to keep it low. Besides the adoption of Kotlin, one big change in Store is ditching RxJava in favour of the structured concurrency paradigm implemented in Kotlin reactive streams. Structured concurrency encapsulates concurrent tasks in programming constructs that clearly define entry and exit points and the overall control flow. This, says Nakhimovich, has a big impact on ensuring all resources used in concurrent tasks are properly freed whenever the task ends. With RxJava publish/subscribe approach, the programmer is responsible for unsubscribing, which could lead to errors.

The big problem with RxJava’s approach to scoping background operations is that it’s too easy for engineers to forget to call dispose . Failing to dispose of active subscriptions directly leads to memory leaks.

Store includes support for memory caching with TTL and size policies, disk caching, multi-casting of responses, explicitly skipping the cache to fetch new data from the data source, and more.

If you are interested in learning more about Store do not miss Nakhimovich, which provides an introductory walk-though of its API. You can access JetPack documentation on Google Android Developer site.



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here