androidandroid-studioandroid-activityandroid-manifestnavigation-architecture

Completely restart android app including application class


I want to restart the application after the user changes language within the application.

I will restart the Application class and main activity specified in the AndroidManifest.xml, so how can I start the application as if I were reopening it from scratch?


Solution

  • This restarts the whole application

    val intent = Intent(context, MainActivity::class.java)
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    context.startActivity(intent)
    context.finish()
    Runtime.getRuntime().exit(0)