Skip to content

Instantly share code, notes, and snippets.

View jaozinfs's full-sized avatar

João Victor Chaves de Oliveira jaozinfs

View GitHub Profile
suspend fun fetchTwoDocs() = coroutineScope {
val deferreds = listOf(
async { fetchDoc(1) },
async { fetchDoc(2) }
)
deferreds.awaitAll()
}
fun main() = runBlocking {
val handler = CoroutineExceptionHandler { _, exception ->
println("CoroutineExceptionHandler hot $exception")
}
val job = launch(handler) {
supervisorScope {
launch {
downloadImage()
println("finish download 1")
}
fun main() = runBlocking {
val job = launch {
updateUi()...
coroutineScope {
launch {
downloadImage()
}
launch {
downloadSounds()
fun main() = runBlocking {
val job = launch {
launch {
downloadImage()
}
launch {
downloadSounds()
}
println("finish downloads")
fun main() = runBlocking {
val job1 = launch {
delay(2000)
downloadData()
print("Completed Job 1")
}
val job2 = launch {
delay(2000)
syncUserDetails()
fun main() = runBlocking {
val job = launch {
delay(2000)
updateDataBase()
print("Completed Job")
}
job.join()
println("Finish")
readDataBase()
}
fun main() = runBlocking {
val job = launch {
delay(2000)
print("Completed Job")
}
println("Finish")
}
abstract fun addMenuProvider(
@NonNull provider: MenuProvider,
@NonNull owner: LifecycleOwner,
@NonNull state: Lifecycle.State
): Unit
class ExampleFragment : Fragment(R.layout.fragment_example) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val menuHost: MenuHost = requireActivity()
menuHost.addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
// Add o menu aqui
menuInflater.inflate(R.menu.example_menu, menu)
}
class ExampleActivity : ComponentActivity(R.layout.activity_example) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Add menu items without overriding methods in the Activity
addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
// Add menu items here
menuInflater.inflate(R.menu.example_menu, menu)