当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
1081 Check Password (15 points)
pyqt5实现仪表盘
magical_spider远程采集方案
3.2 - classification - Logistic regression
1.2-误差来源
研发了 5 年的时序数据库,到底要解决什么问题?
你有对象类,我有结构体,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang结构体(struct)的使用EP06
快速幂,逆元的求解
Conditional statements in TF; where()
零基础SQL教程: 基础查询 05
Four states of Activity
LoRa芯片的特征
go sqlx 包
欢迎加入sumarua网络安全交流社区
2.1 - Gradient Descent
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
8、Mip-NeRF
老干妈创始人陶华碧现身直播间,70岁“国民女神”拥抱直播电商
【云原生】云原生在网络安全领域的应用
分门别类输入输出,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang基本数据类型和输入输出EP03