MainActivity.kt package com.example.coroutine import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_main.* import kotlinx.coroutines.* import java.io.BufferedReader import java.io.InputStreamReader import java.net.URL class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // url to get html val url:URL = URL("https://developer.android.com/") button.setOnClickListener { // creates a coroutine and returns its future result // as an implementation of deferred // async task to get html as string from url val result: Deferred = GlobalScope.async { url.getHtml() } // global scope is used to launch top-level coroutines which are // operating on the wh...
Android, .NET C#, Flutter, and Many More Programming tutorials.