Skip to content

Instantly share code, notes, and snippets.

Install-Module oh-my-posh -Scope CurrentUser -SkipPublisherCheck
Install-Module posh-git -Scope CurrentUser
Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck

https://ohmyposh.dev/docs

notepad.exe $PROFILE

Android 如何使用协程

安卓上, 协程可以帮忙解决两大问题:

  • 管理长时间运行的任务, 这些任务可能阻塞主线程, 导致 UI 卡顿.
  • 在主线程上安全地调用网络或磁盘操作.

安卓上使用协程的最好方式是使用官方的架构组件, 它们提供了对协程的支持. 目前 ViewModel, Lifecycle, LiveData , Room 组件提供了对协程一等的支持.

ViewModelScope

ViewModel 的支持主要是在 ViewModel 上提供了一个称为 ViewModelScopeCoroutineScope , 所有在 ViewModelScope 上启动的协程, 当 ViewModelScope 销毁时自动取消. 这样可以有效防止忘记取消任务时导致的资源泄漏.