当前位置:网站首页>关于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,开多个线程去执行耗时操作,就很难管理
边栏推荐
- NFT 的价值从何而来
- Strongly recommend an easy-to-use API interface
- Attitude solution - gyroscope + Euler method
- Get Pinduoduo product information operation details
- 你是如何做好Unity项目性能优化的
- Depth (relay supervision)
- Spatial Pyramid Pooling -Spatial Pyramid Pooling (including source code)
- How Unity handles C# under the hood
- Do not add the is prefix to the variables of the boolean type in the POJO class of the Alibaba specification
- opencv实现数据增强(图片+标签)平移,翻转,缩放,旋转
猜你喜欢

Douyin get douyin share password url API return value description

Discourse's Close Topic and Reopen Topic

【预约观看】Ambire 智能钱包 AMA 活动第四期即将举行

淘宝sku API 接口(PHP示例)

A used in the study of EEG ultra scanning analysis process

How to choose professional, safe and high-performance remote control software

Douyin share password url API tool

Pinduoduo API interface (attach my available API)

从苹果、SpaceX等高科技企业的产品发布会看企业产品战略和敏捷开发的关系

皮质-皮质网络的多尺度交流
随机推荐
Redis测试
linux 安装mysql服务报错
Taobao sku API interface (PHP example)
Multiscale communication in cortical-cortical networks
unable to extend table xxx by 1024 in tablespace xxxx
进制转换间的那点事
MindManager2022全新正式免费思维导图更新
Douyin share password url API tool
Douyin API interface
Tidb二进制集群搭建
JVM学习——3——数据一致性
3GPP LTE/NR信道模型
联想集团:2022/23财年第一季度业绩
一种用于EEG超扫描研究的分析流程
Daily SQL - find each of the students school gpa minimum (window)
ssh服务攻防与加固
sql--Users who have purchased more than 3 times (inclusive) within 7 days (including the current day), and the purchase amount in the past 7 days exceeds 1,000
Coordinate system in navigation and positioning
【sdx62】XBL设置共享内存变量,然后内核层获取变量实现
软件测试基本流程有哪些?北京专业第三方软件检测机构安利