Android app restart
programmatic app restart
Android development
Android programming
app lifecycle

How do I programmatically restart an Android app?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Programmatically restarting an Android app is usually a sign that the app is trying to recover from a major state change such as language switching, a sign-out flow, or a fatal configuration reset. Android does not provide a clean “restart the whole app” button as a normal user-interface pattern, so the safest answer depends on what you are actually trying to refresh.

In many cases you should recreate the current activity, not restart the process. If you truly need an application-level restart, relaunch the launcher activity and clear the task stack.

Prefer the Smallest Restart That Solves the Problem

If your goal is only to refresh the UI after a theme or locale change, use activity recreation:

kotlin
1class MainActivity : AppCompatActivity() {
2    fun refreshUi() {
3        recreate()
4    }
5}

That is much safer than killing the app process. It keeps Android in control of lifecycle management and avoids surprising state loss.

Relaunch the App Task

If you really need to restart the visible app flow, create an intent for the launch activity, clear the existing task, and finish the current activity stack.

kotlin
1import android.content.Intent
2import androidx.appcompat.app.AppCompatActivity
3
4fun AppCompatActivity.restartApp() {
5    val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
6        ?: return
7
8    val restartIntent = Intent.makeRestartActivityTask(launchIntent.component)
9    startActivity(restartIntent)
10    finishAffinity()
11}

This relaunches the entry activity as a fresh task. For many “restart” requirements, this is the most practical implementation.

When a Full Process Exit Is Used

Some apps also terminate the current process after launching the restart intent so that stale singletons or caches cannot survive. That approach is more aggressive and should be reserved for cases where task relaunch alone is not enough.

kotlin
1import kotlin.system.exitProcess
2
3fun AppCompatActivity.hardRestartApp() {
4    val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
5        ?: return
6
7    val restartIntent = Intent.makeRestartActivityTask(launchIntent.component)
8    startActivity(restartIntent)
9    finishAffinity()
10    exitProcess(0)
11}

This works, but it is a last resort. Forcefully ending the process can interrupt background work, analytics flushing, or pending disk writes.

Decide Based on the Real Requirement

Before writing restart code, classify the problem:

  • UI needs to redraw: use recreate()
  • user should return to the first screen after sign-out: clear the back stack and launch the entry activity
  • major configuration or dependency graph changed: relaunch the task, possibly with process exit as a last step

The wrong choice usually comes from treating every refresh problem as a full app restart problem.

Testing the Behavior

Always test on a real device and verify these details:

  • the back button does not reopen old screens
  • pending dialogs do not reappear in a broken state
  • session data is cleared only when intended
  • restart logic does not loop if it runs during app startup

A restart flow that looks correct in a minimal demo can still fail if your app uses deep links, notifications, or multiple activities.

Common Pitfalls

  • Killing the process when recreate() would have been enough.
  • Restarting from a background context without a valid activity.
  • Forgetting to clear the task stack, which leaves old activities behind.
  • Triggering restart during initialization and causing an infinite restart loop.
  • Assuming process termination is a normal Android UX pattern.

Summary

  • Android does not have a single built-in “restart app” API meant for everyday use.
  • Use recreate() when you only need to refresh one activity.
  • For an app-level restart, relaunch the launcher activity with a fresh task.
  • Only terminate the process if relaunching the task is not enough.
  • Choose the smallest lifecycle change that solves the real problem.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.