当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
opengauss创建用户权限问题
经典论文-MobileNet V1论文及实践
笔试题大疆08.07
Two startup methods and differences of Service
2022-08-10 mysql/stonedb-慢SQL-Q16-耗时追踪
JRS303-数据校验
IQUNIX A80 exploring TTC金粉 初体验
项目1-PM2.5预测
1002 Write the number (20 points)
【43. 字符串相乘】
3.1-分类-概率生成模型
如何通过 IDEA 数据库管理工具连接 TDengine?
Active users of mobile banking grew rapidly in June, hitting a half-year high
查找最新人员工资和上上次人员工资的变动情况
3.2 - classification - Logistic regression
关于架构的认知
流式结构化数据计算语言的进化与新选择
零基础SQL教程: 主键、外键和索引 04
用 Antlr 重构脚本解释器
迷你图书馆系统(对象+数组)









