当前位置:网站首页>Interview questions about Android Service
Interview questions about Android Service
2022-08-11 08:11:00 【is a small A】
It has been two months since the last interview. I remembered the interview topic and wanted to share it with you. I hope you can use it.
1.Can the onCreate callback function of Service do time-consuming operations?
No
Service's onCreate is called in the main thread (ActivityThread), and time-consuming operations will block the UI
If you need to do time-consuming operations - thread and Handler mode
2. Do you know IntentService and in what scenarios do you use IntentService?
Compared with the parent class Service, the biggest feature of IntentService is that it can directly perform time-consuming operations in its callback function onHandleIntent, without having to open a thread
Rationale:
The member variable Handler of IntentService already belongs to the worker thread when it is initialized, and then handleMessage, including onHandleIntent and other functions run in the worker thread
If the understanding of IntentService is limited to this, there will be a point of view that IntentService is very tasteless, because it is not troublesome to open threads in Service for time-consuming operations
IntentService Features:
It is to call the onHandleIntent function multiple times (that is, there are multiple time-consuming tasks to be executed), and multiple time-consuming tasks will be executed in sequence
The principle is that its built-in Handler is associated with the task queue, and the Handler takes the task execution through the looper and executes it sequentially
This feature can solve the problem that multiple time-consuming tasks need to be executed sequentially.And if you only use service and open multiple threads to perform time-consuming operations, it will be difficult to manage
边栏推荐
- go 操作MySQL之mysql包
- 如何仅更改 QGroupBox 标题的字体?
- There may be fields that cannot be serialized in the abnormal object of cdc and sqlserver. Is there anyone who can understand it? Help me to answer
- FPGA 20个例程篇:11.USB2.0接收并回复CRC16位校验
- 【415. 字符串相加】
- C语言-结构体
- 1061 True or False (15 points)
- 【TA-霜狼_may-《百人计划》】图形3.7.2 command buffer简
- Kotlin算法入门兔子数量优化及拓展
- 欧拉函数(用欧拉筛法求欧拉函数)
猜你喜欢
Redis 只会用缓存?20种妙用让同事直呼牛X(荣耀典藏版)
IQUNIX A80 exploring TTC金粉 初体验
Item 2 - Annual Income Judgment
通过记账,了解当月收支情况
My creative anniversary丨Thank you for being with you for these 365 days, not forgetting the original intention, and each is wonderful
golang 字符串操作
excel 透视表 值显示内容 不显示计数
tf.cast(), reduce_min(), reduce_max()
2.1-梯度下降
1.1-回归
随机推荐
2022年值得关注的NFT发展趋势
关于#sql#的问题:怎么将下面的数据按逗号分隔成多行,以列的形式展示出来
机器学习(三)多项式回归
【415. 字符串相加】
Two state forms of Service
1071 Small Gamble (15 points)
1056 Sum of Combinations (15 points)
RestTemplate工具类
CIKM 2022 AnalytiCup Competition: Federal Heterogeneous Task Learning
链式编程注解
redis operation
快速幂,逆元的求解
项目1-PM2.5预测
C Primer Plus(6) 中文版 第1章 初识C语言 1.7 使用C语言的7个步骤
基于微信小程序的租房小程序
1.1-Regression
零基础SQL教程: 基础查询 05
2.1-梯度下降
零基础SQL教程: 主键、外键和索引 04
1076 Wifi Password (15 points)