当前位置:网站首页>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
边栏推荐
- tf.reduce_mean() and tf.reduce_sum()
- JRS303-Data Verification
- Four operations in TF
- 1.1-Regression
- 场地预订系统,帮助场馆提高坪效
- 2022-08-10 mysql/stonedb-慢SQL-Q16-耗时追踪
- 【Day_13 0509】▲跳石板
- Mysql JSON对象和JSON数组查询
- 3.2 - classification - Logistic regression
- 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
猜你喜欢
随机推荐
几何EX3 功夫牛宣布停售,入门级纯电产品为何总成弃子
零基础SQL教程: 基础查询 05
场地预订系统,帮助场馆提高坪效
The most complete documentation on Excel's implementation of grouped summation
3.2 - classification - Logistic regression
兼容并蓄广纳百川,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang复合容器类型的声明和使用EP04
基于微信小程序的租房小程序
进阶-指针
剑指offer专项突击版第26天
Redis 只会用缓存?20种妙用让同事直呼牛X(荣耀典藏版)
Project 1 - PM2.5 Forecast
Four operations in TF
2.1-梯度下降
【云原生】云原生在网络安全领域的应用
关于#sql#的问题:怎么将下面的数据按逗号分隔成多行,以列的形式展示出来
C Primer Plus(6) 中文版 第1章 初识C语言 1.7 使用C语言的7个步骤
1081 Check Password (15 points)
1002 Write the number (20 points)
Swagger简单使用
用 Antlr 重构脚本解释器







