什么是Android中的JobService [英] What is a JobService in Android
问题描述
我正在检查Android-L开发人员SDK中的最新示例. android-L/ui/views/Clipping/ClippingBasic
中有一个名为 TestJobService 的示例类.它从 JobService 扩展而来转向从服务开始.我看到 JobService 是android.jar中的一个类,但是我无法在开发指南中找到任何信息,也无法在Android源代码
I am inspecting the latest samples in Android-L developer SDK. There is a sample class in android-L/ui/views/Clipping/ClippingBasic
called TestJobService. It extends from JobService, which in turn extends from Service. I see that JobService is a class in android.jar, but I cannot find any information on it in the dev guides, nor in the Android sourcecode www.androidxref.com. Has anybody seen this class or know what it's purpose is?
推荐答案
这是一种新的服务类型,根据计划根据系统条件(例如,空闲,插入)运行的任务会被调用.
It's a new type of service, that is invoked for tasks that are scheduled to be run depending on system conditions (e.g. idle, plugged in).
JobScheduler回调的入口点.
Entry point for the callback from the JobScheduler.
这是处理异步请求的基类
先前预定的.您有责任覆写
onStartJob(JobParameters)
,这是您执行工作的地方
逻辑.
This is the base class that handles asynchronous requests that were
previously scheduled. You are responsible for overriding
onStartJob(JobParameters)
, which is where you will implement your job
logic.
基本上,您将创建一个描述这些条件的JobInfo
对象(使用JobInfo.Builder
),并设置必须执行的服务的组件名称.
You basically create a JobInfo
object that describes these conditions (with JobInfo.Builder
) and set the component name of the service that must be executed.
要安排它们,您需要JobScheduler
,您可以通过Context.getSystemService(Context.JOB_SCHEDULER_SERVICE)
进行访问.
To schedule them, you need the JobScheduler
, which you can access with Context.getSystemService(Context.JOB_SCHEDULER_SERVICE)
.
顺便说一句, L预览文档在这里,如果您没有的话.不知道.
By the way, L Preview Documentation is here, in case you didn't know about it.
更新: 这是有关JobService的文档: https://developer.android.com/reference/android/app/job/JobService.html
UPDATE: Here is the doc about JobService: https://developer.android.com/reference/android/app/job/JobService.html
这篇关于什么是Android中的JobService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!