bridge
An open source library for avoiding the pitfalls of Android state saving and restoration.
Why we built it.
Many Android developers have long leveraged the Android state saving and restoration
framework to save network-related data to avoid unnecessary network requests after
configuration changes and when restoring apps from a background state. There was always
a limitation to the amount of data that could be saved, but that limit originally
manifested as a silent failure to properly save and restore state—a graceful outcome
that most developers could tolerate. In Android Nougat, however, many developers were
blindsided when that limitation was upgraded to a hard crash via the infamous TransactionTooLargeException
.
While Google gave new guidance on how to avoid situations like these with the introduction of the Android Architecture Components, the Android team at Livefront felt it was necessary to provide a tool to the broader community that solves this problem with as little code change as possible. This not only helps to quickly solve the problem on existing projects without a significant code refactor, but is valuable to any new project that wants to handle state saving and restoration in a more traditional way without needing to manually create and maintain a local database.
How it works.
Rather than sending your saved data to the Android OS, Bridge stores your data as a Bundle in memory (for quick retrieval after configuration changes) and employs a simple trick to generically write Bundles to disk (for access after process death and restoration). In order to match Activities and Fragments with the corresponding saved data managed by Bridge, Bridge also hooks into the existing saved state framework to store and retrieve keys that uniquely identify that state. In this way, Bridge works both with and around the Android OS state saving framework in order to provide the best possible results.
For more details, check out our Medium article.
How to use it.
Using Bridge is simple, especially if you are already using or are familiar with annotation-based state saving frameworks like Icepick.
Check out the project on Github for more details.
Built by Livefront.
Livefront is a digital product consultancy. We’re trusted by some of the world’s most admired companies to drive strategy, design, and engineering for their core digital experiences. They partner with us to move faster, think bigger, and design products people love.
Learn more