Last active
February 16, 2020 15:46
-
-
Save mochadwi/9091d3d5e1789db5669adc51df2533bd to your computer and use it in GitHub Desktop.
Wrapper to handle nullable activity and returns non-null activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Activity?.safeActivity(action: Activity.() -> Unit) { | |
val isActivityStillRuns = this != null && (!this?.isDestroyed() || !this?.isFinishing()) | |
if (isActivityStillRuns) { | |
action.invoke() | |
} | |
} | |
// usage: | |
fun initSomething() = [email protected] { | |
val adapter = YourAdapter(this, listOf()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment