当前位置:网站首页>Kotlin协程协程作用域,CoroutineScope MainScope GlobalScope viewModelScope lifecycleScope 分别代表什么
Kotlin协程协程作用域,CoroutineScope MainScope GlobalScope viewModelScope lifecycleScope 分别代表什么
2022-06-12 03:36:00 【安果移不动】
首先定义协程必须要制定其CoroutineScope
他会跟踪所有协程。同样他还可以取消由它所启动的所有协程。
GlobalScope
声明周期是process级别的。即使Activty与Fragment已经被销毁,协程仍然在运行。
MainScope 通常在 在Activity中使用。 在onDestory 要记得手动销毁掉。
viewModelScope 只能在ViewModel中使用。绑定viewModel的生命周期
lifecycleScope。只能在Activity、Fragment中使用。并且会和Activity、Fragment生命周期进行绑定。
MainScope 使用案例
边栏推荐
- 消息队列概述
- 【mysql】mysql安装
- Final summary of addition, deletion, modification and query
- 认真工作对自己到底意味着什么?
- 2020-12-10
- VIM command Encyclopedia
- PostgreSQL basic introduction and deployment
- 关于 国产麒麟Qt编译报错“xxx.pri has modification time xxxx s in the futrue“ 的解决方法
- mysql/oracle 以唯一时间为分界,小于等于该时间求和,大于该时间求和
- Three ways for ORALCE to process column to row conversion and finally generate table style data
猜你喜欢

Special materials | household appliances, white electricity, kitchen electricity

2020-12-06

2020-12-10

Concept and introduction of microservice

Image mosaic based on transformation matrix

$LastExitCode=0, but $?= False in PowerShell. Redirecting stderr to stdout gives NativeCommandError

Detailed explanation of data platform SQL development and function use

云原生概述

The rise of another domestic mobile phone chip is close to the height reached by Huawei

Infinite loop judgment method;
随机推荐
In 2022, why is there a market for Shanzhai products?
Yyds dry inventory MySQL learning - how transactions are isolated
ics-07
Detailed explanation of data platform SQL development and function use
postgresql基本介绍以及部署使用
Yu Xia looks at win system kernel -- debugging
2020-12-06
Absolute positioning three ways to center the box
Hacker + marathon =? Hacker marathon?
2020-12-17
绝对定位使盒子居中显示的三种方式
Redis gets the set of keys prefixed with XXX
Notes relatives à l'application du certificat de l'AC et de la paire de clés
In 2022, don't you know the difference between arrow function and ordinary function?
[DFS "want" or "don't"] seek subsets; Seeking combination
Functions (arguments, formal parameters, bubbling)
Laravel 8 selects JWT for interface verification
Special information | liquor (Baijiu, beer, wine)
魏武帝 太祖知不可匡正,遂不复献言
What is a request response pair called? [repeat] - what is a request response pair called? [duplicate]