Skip to content

Instantly share code, notes, and snippets.



Last active Feb 16, 2020
What would you like to do?
Wrapper to handle nullable activity and returns non-null activity
fun Activity?.safeActivity(action: Activity.() -> Unit) {
val isActivityStillRuns = this != null && (!this?.isDestroyed() || !this?.isFinishing())
if (isActivityStillRuns) {
// usage:
fun initSomething() = this@YourActivity.safeActivity {
val adapter = YourAdapter(this, listOf())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment