Skip to content

Instantly share code, notes, and snippets.

@travisdachi
Created August 11, 2016 10:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travisdachi/cbe44e614cba26977b5ee2b123d66bd9 to your computer and use it in GitHub Desktop.
Save travisdachi/cbe44e614cba26977b5ee2b123d66bd9 to your computer and use it in GitHub Desktop.
class SomeActivity : Activity() {
val f: Foo by lazy { createFoo() } // put your initialization block here
fun onCreate(bundle: Bundle?) {
f.foo() // f will be created here and it's a val so you can't change it
f // or you can call a getter just to initialize it
}
fun createFoo() = Foo(this)
// this is useful when you need a context after the activity is created
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment