Android IntentService deprecated|笔记

Posted aikongmeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android IntentService deprecated|笔记相关的知识,希望对你有一定的参考价值。

先回顾一下,
面试一般都喜欢问IntentService 原理, 个人觉的啥是原理,不就是源码吗?
就下面几行源码,就能出滋生出来,几道面试题:
什么IntentService继承service阿,自带looper阿,还会自己停止阿,不知道这源码一眼j就可以看出来的东西,面这东西干啥,是要考背源码吗?

重点是这个东西,它在API 26的时候被 Deprecated

Deprecated IntentService is subject to all the background execution limits imposed with android 8.0 (API level 26).
Consider using androidx.work.WorkManager or androidx.core.app.JobIntentService,
which uses jobs instead of services when running on Android 8.0 or higher.

JobIntentService好的我们来看下这个加了个Job的IntentService

Helper for processing work that has been enqueued for a job/service. 
When running on Android O or later,
the work will be dispatched as a job via JobScheduler.enqueue. When running on older versions of the platform, it will use Context.startService.

机器翻译:
处理已排队等候作业/服务的工作的助手。
当运行在Android O或更高版本时,
该工作将通过JobScheduler.enqueue作为作业分发。在旧版本的平台上运行时,它将使用Context.startService。
尴尬的是这个类也要被弃用。
在Android Jetpack Android O或更高版本中,这个类已经被弃用
得研究一圈,回到了 jetpack WorkManager
WorkManager 无缝集成 RxJava协程,并可灵活地插入您自己的异步 API。

WorkManager.getInstance(...)
    .beginWith(listOf(workA,workB))
    .then(workC)
    .enqueue()

下转官方中文文档
https://developer.android.com/topic/libraries/architecture/workmanager

以上是关于Android IntentService deprecated|笔记的主要内容,如果未能解决你的问题,请参考以下文章

Android 多线程之IntentService 完全详解

Android IntentService

Android Training - 使用IntentService运行任务(Lesson 2 - 发送任务给IntentService)

Android - 多次运行 IntentService

Android面试收集录9 IntentService详解

Android中使用IntentService运行后台任务