Skip to content

Instantly share code, notes, and snippets.

@elizarov
Created May 12, 2017 10:03
Show Gist options
  • Save elizarov/0b3e3386d304478368b3eb0380b6f25a to your computer and use it in GitHub Desktop.
Save elizarov/0b3e3386d304478368b3eb0380b6f25a to your computer and use it in GitHub Desktop.
Perform some long-running initialization in background thread
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val application = this
launch(UI) { // start a new coroutine in Android UI context
// switch to background thread for some long-running initialization
run(CommonPool) { AndroidThreeTen.init(application) }
// then init UI
initUI()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment