Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Modern Android App Architecture with JetPack and Dropbox Store

Modern Android App Architecture with JetPack and Dropbox Store

This item in japanese

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 is a library for "effortless, reactive data loading" that was originally written in Java. Store has since been rewritten in Kotlin on the foundations provided by Coroutines and Flow. Along with the 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. First, JetPack aims to leverage advanced Kotlin features in order to reduce boilerplate code programmers have to write. Second, it also provides higher-level abstractions on top of those found in the Android SDK, such as Fragments and Activities, in order to allow developers to express complex tasks in a simpler way.

JetPack includes a number of components that can be used independently of 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. This in demonstrated in the following image.

JetPack provides most of the components to create an Android app following Google's 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.

Dropbox Store enables the connection of an 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 usage low. Besides the adoption of Kotlin, another big change in the Store code is the ditching of 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 time to live (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's Android Developer site.

Rate this Article