Skip to content

Instantly share code, notes, and snippets.

@adityawibisana
Created July 9, 2019 12:30
Show Gist options
  • Save adityawibisana/6056590a5e217a3d2a8372d6efd53a59 to your computer and use it in GitHub Desktop.
Save adityawibisana/6056590a5e217a3d2a8372d6efd53a59 to your computer and use it in GitHub Desktop.
simple custom function to run on UI and background respectively
//run this on default background thread
runOnDefaultThread({
firstNote = NoteRepository.getOrCreateFirstNote(applicationContext)
firstNoteLive = NoteRepository.getLiveDataNoteById(applicationContext, firstNote.id)
//run on main thread
runOnUiThread {
firstNoteLive.observe(this, Observer<Note> {
Log.v(TAG, "First note is changed, value: ${it.content}")
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment