Maintaining Activity Lifecycle in Android
August 27, 2019

A common problem people run into with Activities are handling runtime configuration changes. This situation ought to sound familiar:
- The user initiates a network request in an Activity.
- The user rotates the screen.
- The Activity is destroyed and recreated with a new configuration.
- Your network request is lost because it only had references to the initial Activity.
The solution is quite simple: if the logic needs to live beyond the duration of the lifecycle, put it somewhere outside the lifecycle.
For example, your network request should deliver its results to some intermediary such as an in-memory cache. Then the Activity can retrieve the results when complete.
People often confuse themselves by thinking a specific tool is the solution to the problem when it’s just an implementation detail. “How does RxJava handle config changes?” is a question I’ve been asking many times, but to me the question makes little sense because RxJava has no explicit API for Android. It’s just a library for handling streams of data.
You can certainly use RxJava in your solution. The reactive way to inform the Activity of UI changes is to create an Observable<Data> and subscribe. But that alone is not the solution to config changes; if your Observable<Data> was contained in the Activity you’d still have the same problem as before! The actual solution is in ensuring your Observable<Data> lives somewhere outside of the lifecycle.
It’s simpler (at least in my mind) to separate out the core solution from the tools used to implement it. The core solution is writing logic that lives beyond a single lifecycle. The way you do that is up to you.
You can read more about maintaining activity lifecycle in android here.
At Emqube we focus on building high quality mobile apps. Contact us if you would like us to build an app for you.
Latest Posts

June 01, 2026
The Rejuvenating Effect of Shinrin-Yoku
As we spend most of our time indoors inside our homes, offices and vehicles, we’re constantly glued to our screens and tech devices. Compulsive viewing of our phone updates and...

May 20, 2026
Content Marketing Will Rule
More than ever before, customers are turning to online search engines to find information about products and services, discover solutions to problems and explore answers to queries they have… Without...

December 26, 2024
Get rid of Your Inner Enemies in 2025
In a world shaken by war and political chaos, let us choose to welcome the new year with higher thinking and deeper understanding to ensure peace and unity. While we...
Ready to build your customized software?
Talk to our Business Applications Team in Dubai