Last active
December 22, 2022 06:01
-
-
Save dandvl/cbd34cf78649fea18b2d1b044b091954 to your computer and use it in GitHub Desktop.
CR Launch Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.util.Log | |
import androidx.lifecycle.lifecycleScope | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.launch | |
import kotlin.system.measureTimeMillis | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
lifecycleScope.launch { | |
val timeSpent = measureTimeMillis { | |
var result1 = "" | |
var result2 = "" | |
val answer1 = launch { result1 = longProcess() } | |
val answer2 = launch { result2 = longProcess2() } | |
answer1.join() | |
answer2.join() | |
Log.d("test", result1) | |
Log.d("test", result2) | |
} | |
Log.d("test", "m: $timeSpent") | |
} | |
} | |
} | |
suspend fun longProcess(): String { | |
delay(2000L) | |
return "Answer 01" | |
} | |
suspend fun longProcess2(): String { | |
delay(4000L) | |
return "Answer 02" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment