当前位置:网站首页>关于Android Service服务的面试题
关于Android Service服务的面试题
2022-08-11 06:44:00 【是小A】
距离上一次面试的已经过去两个月了,想起来面试的题目,想给大家分享一下,希望大家能用到。
1.Service的onCreate回调函数可以做耗时的操作吗?
不可以
Service的onCreate是在主线程(ActivityThread)中调用的,耗时操作会阻塞UI
如果需要做耗时的操作—— 线程和Handler方式
2. 是否知道IntentService,在什么场景下使用IntentService?
IntentService相比父类Service而言,最大特点是其回调函数onHandleIntent中可以直接进行耗时操作,不必再开线程
原理:
IntentService的成员变量 Handler在初始化时已属于工作线程,之后handleMessage,包括onHandleIntent等函数都运行在工作线程中
如果对IntentService的了解仅限于此,会有种IntentService很鸡肋的观点,因为在Service中开线程进行耗时操作也不麻烦
IntentService特点:
就是多次调用onHandleIntent函数(也就是有多个耗时任务要执行),多个耗时任务会按顺序依次执行
原理是其内置的Handler关联了任务队列,Handler通过looper取任务执行是顺序执行的
这个特点就能解决多个耗时任务需要顺序依次执行的问题。而如果仅用service,开多个线程去执行耗时操作,就很难管理
边栏推荐
猜你喜欢

Implementation of FIR filter based on FPGA (5) - FPGA code implementation of parallel structure FIR filter

【@网络工程师:用好这6款工具,让你的工作效率大翻倍!】

Amazon Get AMAZON Product Details API Return Value Description

每日sql--统计员工近三个月的总薪水(不包括最新一个月)

Spatial Pyramid Pooling -Spatial Pyramid Pooling (including source code)

Taobao product details API interface

Douyin API interface

MySQL使用GROUP BY 分组查询时,SELECT 查询字段包含非分组字段

语音信号处理:预处理【预加重、分帧、加窗】

3GPP LTE/NR信道模型
随机推荐
What are the things that should be planned from the beginning when developing a project with Unity?How to avoid a huge pit in the later stage?
淘宝商品详情API接口
Redis源码:Redis源码怎么查看、Redis源码查看顺序、Redis外部数据结构到Redis内部数据结构查看源码顺序
微信小程序功能上新(2022.06.01~2022.08.04)
NTT的Another Me技术助力创造歌舞伎演员中村狮童的数字孪生体,将在 “Cho Kabuki 2022 Powered by NTT”舞台剧中首次亮相
李沐d2l(十)--卷积层Ⅰ
Daily SQL - find each of the students school gpa minimum (window)
概念名词解释
When MySQL uses GROUP BY to group the query, the SELECT query field contains non-grouping fields
Daily sql-statistics of the number of professionals (including the number of professionals is 0)
拼多多API接口大全
伦敦银规则有哪些?
C语言每日一练——Day02:求最小公倍数(3种方法)
常见激活函数及其导数
Daily sql-employee bonus filtering and answer rate ranking first
How to choose professional, safe and high-performance remote control software
Redis + lua implements distributed interface current limiting implementation scheme
【@网络工程师:用好这6款工具,让你的工作效率大翻倍!】
淘宝sku API 接口(PHP示例)
网络电话软件或迎整顿 “免费”通话须迈安全关