Skip to content

Instantly share code, notes, and snippets.

@vargasgabriel
Forked from easterapps/ActivityRestart.kt
Created January 25, 2022 17:50
Show Gist options
  • Select an option

  • Save vargasgabriel/c395da1566904f7d338e48ea9dff12f1 to your computer and use it in GitHub Desktop.

Select an option

Save vargasgabriel/c395da1566904f7d338e48ea9dff12f1 to your computer and use it in GitHub Desktop.
restart android application programmatically
fun triggerRestart(context: Activity) {
val intent = Intent(context, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
if (context is Activity) {
(context as Activity).finish()
}
Runtime.getRuntime().exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment