How to restart Activity in Android
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Restarting an Android activity usually means destroying the current instance and creating a new one with the same intent or updated configuration. That can be useful after a theme change, locale change, or when you want to reset transient UI state. The correct technique depends on whether you want a full recreation, a data refresh, or a navigation-level restart.
Use recreate() for a True Activity Restart
The simplest built-in option is recreate(). It tells Android to destroy the current activity instance and create it again. The lifecycle runs through onPause, onStop, onDestroy, and then a new onCreate.
This is the right choice when the same activity should come back with the same intent, but with fresh views and resources.
Restart with a New Intent When Inputs Must Change
If you need to restart the activity and pass new extras, launch a new instance and close the current one.
This approach is useful when the replacement activity should start with different state than the original one. It is also clearer than trying to mutate a lot of fields before calling recreate().
If you do not want a transition flash, you can suppress animations:
Do Not Restart When a Simple Refresh Is Enough
A full activity restart is heavier than reloading data into existing views. If the user only needs fresh content, update the screen in place instead of recreating the activity.
This avoids lifecycle churn and usually gives a smoother experience.
Configuration Changes Need Deliberate Handling
Developers often restart an activity after theme or locale changes. That is reasonable, because Android resources such as strings, dimensions, and colors are resolved again when the activity is recreated.
For example, after changing an app setting that affects theme selection:
In contrast, forcing restarts for every small state change is a design smell. Most UI state should survive configuration changes through ViewModel, saved instance state, or persistent storage.
Preserve State You Actually Care About
Restarting destroys the current view hierarchy. If the screen has typed text, scroll position, or other transient state, save it before recreation and restore it afterward.
That gives you the benefits of recreation without losing user work.
Common Pitfalls
- Restarting the activity when only a view refresh is needed.
- Using
finish()andstartActivity()without carrying forward required extras. - Forgetting to preserve user-entered state before recreation.
- Restarting repeatedly inside lifecycle callbacks and causing loops.
- Disabling normal configuration handling with manifest flags when standard recreation would be simpler.
- Treating process restart and activity restart as the same thing. They are not.
Summary
- Use
recreate()when you need the same activity rebuilt cleanly. - Use
finish()plusstartActivity()when the new instance needs different intent data. - Prefer in-place UI refresh when a full restart is unnecessary.
- Save important transient state before recreation.
- Handle theme and configuration changes deliberately rather than restarting by habit.
Related reading
- How to restrict UITextField to take only numbers in Swift?
- How to retrieve the dimensions of a view?
- How to return a result startActivityForResult from a TabHost Activity?
- How to return first 5 objects of Array in Swift?
- How to returning data from a void async call in Swift function
- How to returning data from a void async call in Swift function
- How to right align widget in horizontal linear layout Android?
- How to Rotate a UIImage 90 degrees?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.