当前位置:网站首页>Android kotlin coroutines KTX extension
Android kotlin coroutines KTX extension
2022-06-23 08:35:00 【Susceptible to cold】
This article mainly talks about ,kotlin Assist in ktx Extension on
lifecycle Expand
about lifecycle An extension of , Already in As mentioned in previous articles
Major dependencies
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
viewModel Expand
about viewModel An extension of , Already in As mentioned in previous articles
Major dependencies
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
liveData Expand
Major dependencies
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
The official website links as follows :
Specific examples are as follows :
class MainActivity : AppCompatActivity() {
val user: LiveData<String> = liveData {
// Simulate network requests
var user = getUser()
if (user == "ok") {
// Simulation request succeeded
emit("ok")
} else {
// Impersonation request failed
emit("failed")
}
}
/**
* Simulate network requests
*/
suspend fun getUser(): String {
var ret = withContext(Dispatchers.Default) {
"ok"
}
return ret
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
user.observe(this, {
Log.d("yy--", "name1:$it")
})
}
}边栏推荐
- Production environment server environment setup + project release process
- Kernel log debugging method
- Vulnhub | DC: 4 | [combat]
- PHP serialization and deserialization CTF
- kibana 重建index后,如何恢复Visualizations和 Dashboards
- Install a WGet for your win10
- MySQL common skills
- Basic use of check boxes and implementation of select all and invert selection functions
- 4- draw ellipse, use timer
- How to solve the problem that flv video stream cannot be played and TS file generation fails due to packet loss?
猜你喜欢

Ad object of Active Directory

“方脸老师”董宇辉再回应热度下降:把农产品直播做好让农民受益 考虑去支教

The most commonly used 5-stream ETL mode

论文阅读【Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset】

PCB电路板特性检查项目都有哪些?
![Vulnhub | dc: 3 | [actual combat]](/img/97/e5ba86f2694fe1705c13c60484cff6.png)
Vulnhub | dc: 3 | [actual combat]

数据资产为王,解析企业数字化转型与数据资产管理的关系

谈谈 @Autowired 的实现原理

Vulnhub | DC: 4 |【实战】

INT 104_ LEC 06
随机推荐
Derivation and loading of the trained random forest model
C RichTextBox controls the maximum number of rows
Production environment server environment setup + project release process
Openvino series 19 Openvino and paddleocr for real-time video OCR processing
Set interface and set sub implementation classes
Object.defineProperty() 和 数据代理
复选框的基本使用与实现全选和反选功能
GTEST death test
Explanation on webrtc's stun/turn service in tsingsee green rhino video
Single core driver module
There are some limitations in cluster expansion and contraction
最常用的5中流ETL模式
Qualcomm 9x07 two startup modes
Structure and usage of transform
[cross border e-commerce solutions] lighthouse will be used for pure IP expansion of new business - continuous efforts!
MySQL brochure notes 5 InnoDB record storage structure
Focus! Ten minutes to master Newton convex optimization
The rtsp/onvif protocol video platform easynvr startup service reports an error "service not found". How to solve it?
4-绘制椭圆、使用定时器
Observer mode