当前位置:网站首页>关于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,开多个线程去执行耗时操作,就很难管理
边栏推荐
- ROS 话题通信理论模型
- Implement general-purpose, high-performance sorting and quicksort optimizations
- Daily sql: request for friend application pass rate
- Trill keyword search goods - API
- How to choose professional, safe and high-performance remote control software
- 详述 MIMIC护理人员信息表(十五)
- radix-4 FFT principle and C language code implementation
- concept noun
- Unity3D learning route?
- 【LeetCode每日一题】——682.棒球比赛
猜你喜欢
淘宝商品详情API接口
亚马逊API接口大全
daily sql - query for managers and elections with at least 5 subordinates
已解决EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
技能在赛题解析:交换机防环路设置
Cobbleland 博览会 基础系列 1
常见激活函数及其导数
【预约观看】Ambire 智能钱包 AMA 活动第四期即将举行
Daily sql-statistics of the number of professionals (including the number of professionals is 0)
基于FPGA的FIR滤波器的实现(4)— 串行结构FIR滤波器的FPGA代码实现
随机推荐
博途PLC 1200/1500PLC ModbusTcp通信梯形图优化汇总(多服务器多从站轮询)
prometheus学习4Grafana监控mysql&blackbox了解
【软件测试】(北京)字节跳动科技有限公司二面笔试题
Daily sql--statistics the total salary of employees in the past three months (excluding the latest month)
Taobao API interface reference
Internet phone software or consolidation of attack must be "free" calls security clearance
每日sql -查询至少有5名下属的经理和选举
每日sql-求2016年成功的投资总和
How Unity programmers can improve their abilities
下一代 无线局域网--强健性
2022-08-09 第四小组 修身课 学习笔记(every day)
How to choose professional, safe and high-performance remote control software
Douyin API interface
强烈推荐一款好用的API接口
京东商品详情API调用实例讲解
prometheus学习5altermanager
第一个C函数:如何实现板级初始化?
Taobao product details API interface
恒源云-Pycharm远程训练避坑指南
LeetCode刷题系列 -- 46. 全排列