当前位置:网站首页>关于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,开多个线程去执行耗时操作,就很难管理
边栏推荐
- SQL sliding window
- 已解决EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
- 深度监督(中继监督)
- Redis源码:Redis源码怎么查看、Redis源码查看顺序、Redis外部数据结构到Redis内部数据结构查看源码顺序
- 【@网络工程师:用好这6款工具,让你的工作效率大翻倍!】
- Production and optimization of Unity game leaderboards
- 1688 product interface
- 结合均线分析k线图的基本知识
- 【软件测试】(北京)字节跳动科技有限公司终面HR面试题
- Find the shops that have sold more than 1,000 yuan per day for more than 30 consecutive days in the past six months
猜你喜欢
随机推荐
EasyPlayer针对H.265视频不自动播放设置下,loading状态无法消失的解决办法
国密规范 SM2 SM3 SM4
Get Pinduoduo product information operation details
Daily sql--statistics the total salary of employees in the past three months (excluding the latest month)
Daily sql-seek the sum of successful investments in 2016
Redis源码-String:Redis String命令、Redis String存储原理、Redis字符串三种编码类型、Redis String SDS源码解析、Redis String应用场景
exness:黄金1800关口遇阻,静待美国CPI出炉
LeetCode brushing series -- 46. Full arrangement
1688 product interface
Waldom Electronics宣布成立顾问委员会
sql--7天内(含当天)购买次数超过3次(含),且近7天的购买金额超过1000的用户
Taobao sku API interface (PHP example)
JD.com product details API call example explanation
Edge 提供了标签分组功能
Douyin get douyin share password url API return value description
STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比
数仓开发知识总结
ROS 话题通信理论模型
博途PLC 1200/1500PLC ModbusTcp通信梯形图优化汇总(多服务器多从站轮询)
Unity3D 学习路线?