Skip to content

Instantly share code, notes, and snippets.

@firecatmusic
Created December 21, 2018 05:45
Show Gist options
  • Save firecatmusic/c532a00a06ed87e422c9438527d25bb6 to your computer and use it in GitHub Desktop.
Save firecatmusic/c532a00a06ed87e422c9438527d25bb6 to your computer and use it in GitHub Desktop.
Easily OnBackPressed
class ExitActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
finish()
}
companion object {
fun exit(context: Context) {
val intent = Intent(context, ExitActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
context.startActivity(intent)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment