2

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

  • I'm starting new intent for MainActivity or as another solution I tried activity.recreate() methods but fragments are not initialized when restarting Activity. (I am using Navigation Component)

  • I am using Koin for dependency injection and some scopes are lost and app crash.

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?

enjektor0
  • 483
  • 2
  • 8

1 Answers1

2

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)
Praveen
  • 3,186
  • 2
  • 8
  • 23