This file contains hidden or 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
| /** | |
| * [CoroutineScope] tied to this [LifecycleOwner]'s [Lifecycle]. | |
| * | |
| * This scope will be cancelled when the [Lifecycle] is destroyed. | |
| * | |
| * This scope is bound to | |
| * [Dispatchers.Main.immediate][kotlinx.coroutines.MainCoroutineDispatcher.immediate]. | |
| */ | |
| public val LifecycleOwner.lifecycleScope: LifecycleCoroutineScope | |
| get() = lifecycle.coroutineScope |
This file contains hidden or 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
| dependencies { | |
| ... | |
| implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1") | |
| implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") | |
| } |
This file contains hidden or 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
| fun receiveData(): String { | |
| // Long synchronous work is performed here. | |
| return "Data received" | |
| } |
This file contains hidden or 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
| 21:58:23.164 27359-27359 TAG Data received after 9685.0434 ms. | |
| 21:58:23.168 27359-27359 TAG onCreate completed |
This file contains hidden or 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
| class MainActivity : AppCompatActivity() { | |
| private lateinit var binding: ActivityMainBinding | |
| @OptIn(ExperimentalTime::class) | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| binding = ActivityMainBinding.inflate(layoutInflater) | |
| setContentView(binding.root) |
This file contains hidden or 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
| 22:03:56.665 27504-27504 TAG onCreate completed | |
| 22:04:06.166 27504-27529 TAG Data received after 9491.5399 ms. | |
| 22:04:06.168 27504-27529 AndroidRuntime FATAL EXCEPTION: Thread-2 | |
| java.lang.NullPointerException: Can't toast on a thread that has not called Looper.prepare() |
This file contains hidden or 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
| 22:10:09.755 27650-27650 TAG onCreate completed | |
| 22:10:18.776 27650-27675 TAG Data received after 9006.3558 ms. | |
| 22:10:18.797 27650-27675 AndroidRuntime FATAL EXCEPTION: DefaultDispatcher-worker-1 | |
| java.lang.NullPointerException: Can't toast on a thread that has not called Looper.prepare() |
This file contains hidden or 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
| suspend fun receiveData(): String { | |
| withContext(Dispatchers.IO) { | |
| // Long asynchronous work is performed here. | |
| } | |
| return "Data received" | |
| } |
This file contains hidden or 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
| 22:28:45.709 28976-28976 TAG onCreate completed | |
| 22:29:11.505 28976-28976 TAG Data received after 25069.8728 ms. |
OlderNewer