
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

October 01, 2026
How Much Money a SME Must Spend on Social Media?
It is a question that many founders and marketing managers grapple with. In larger companies, there is a marketing budget that draws the line and gets allocated. In SMEs and...

September 26, 2026
Why Your Next Corporate Video Should Actually Be a Corporate Movie
Many companies follow a standard checklist for their digital presence: a digital brochure, a slide deck for meetings, and eventually a corporate video for their website and exhibitions. The problem...

September 25, 2026
A Brief History of Email as a Marketing Tool
Email marketing survived early spam wars and strict regulations to become the highest ROI channel for digital engagement. From experimental bulk messaging to AI-assisted lifecycle automation, the history of email...
Ready to build your customized software?
Talk to our Business Applications Team in Dubai