Skip to content

Instantly share code, notes, and snippets.

@akshaykalola28
Created April 27, 2023 05:52
Show Gist options
  • Save akshaykalola28/594444ef2c14748a326a4432e7ed1a81 to your computer and use it in GitHub Desktop.
Save akshaykalola28/594444ef2c14748a326a4432e7ed1a81 to your computer and use it in GitHub Desktop.
Extension functions for Start Activity
import android.app.Activity
import android.content.Intent
fun Activity.startActivity(
cls: Class<*>,
finishCallingActivity: Boolean = true,
block: (Intent.() -> Unit)? = null
) {
val intent = Intent(this, cls)
block?.invoke(intent)
startActivity(intent)
if (finishCallingActivity) finish()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment