Android 后台任务

Android 后台任务

  • Service

    Android N(Android 7.0)和 Android O(Android 8.0)系统对Background ServiceBroadcast做了一定的限制,其中的一些限制包括:

    • 不可以在应用处于后台状态时call startService启动Service,否则抛出IllegalStateException
    • 当应用退到后台之后,系统会在一分钟左右的时间继续运行之前所创建启动的后台服务,之后便会被系统标记为空闲状态,并停止该后台服务。

    Above limitations are only background service as foreground service is more visible to users.

    对于Broadcast的限制包括:

    • Android 7.0 中,app can NOT send or receive ACTION_NEW_PICTURE or ACTION_NEW_VIDEO broadcast
    • App targeting Android 7.0 and higher can’t receive CONNECTIVITY_ACTION if it’s declared in manifest
    • From Android O,all implicit broadcast receivers declared in manifest file will not work
  • JobScheduler

    JobScheduler may elect to postpone that work for a bit, but its job are more likely to be differed or interrupted in low-memory situtations ,in doze mode or when they reach a time limit(~10 minutes)

    在API 21引入,但是在API 21和22的版本存在较大bug,所以>=23使用JobScheduler,为了兼容小于23的版本引JobDispatcher,但是来自Google Play Service对于国内来说是不可能

    1. JobIntentService,相比workmanager不能配置像在特定环境下运行job

      在8.0或以后使用JobScheduler.enqueue实现,在8.0前使用startService IntentService实现

      相当于对JobScheduler的封装

  • WorkManager

    所以引入了WorkManager
    在这里插入图片描述

WorkManager使用Processor的决策树

在这里插入图片描述

https://juejin.cn/post/6844903609461653518

https://zhuanlan.zhihu.com/p/37510156

https://stackoverflow.com/questions/59725556/when-to-use-jobintentservice-vs-workmanager

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值