Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 中的定时任务调度 #1823

Merged
merged 3 commits into from
Jul 5, 2017
Merged

Android 中的定时任务调度 #1823

merged 3 commits into from
Jul 5, 2017

Conversation

phxnirvana
Copy link
Contributor

No description provided.

@phxnirvana
Copy link
Contributor Author

卧槽什么速度。。是自动执行的么

@linhe0x0
Copy link
Member

😜

@ilumer
Copy link

ilumer commented Jun 29, 2017

校对认领 @sqrthree

@linhe0x0
Copy link
Member

@ilumer 好的呢 🍺

@wilsonandusa
Copy link
Contributor

校对认领 @sqrthree

@linhe0x0
Copy link
Member

@wilsonandusa 妥妥哒 🍻


Services are especially harmful when it continuously uses device resources even when not performing useful tasks. Above problem increased when those background services are listening for different system broadcasts (like CONNECTIVITY_CHANGE or NEW_PICTURE etc.).
当持续使用设备资源却没有有效任务在执行时,service 便更加有害了。当这些后台服务在监听不同系统广播时(比如 *CONNECTIVITY_CHANGE* 或者 *NEW_PICTURE* 等),问题的严重性还会提升。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些 --> 那些


This API allows to batch jobs when the device has more resources available or when the right conditions are met. All of the conditions can be defined when you’re creating a job. When the criteria declared are met, the system will execute this job on your application’s JobService. *JobScheduler* also defers the execution as necessary to comply with Doze mode and App Standby restrictions.
API 可以在资源充足时或满足条件时批量执行任务。创建任务时可以定义执行的先决条件。当条件满足时,系统会在应用的 JobService 上执行任务。 *JobScheduler* 也取决于系统的打盹模式和应用当前状态。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JobScheduler 的执行也取决于系统的打盹模式和应用当前状态


This library will also works when running device do not have Google play services installed and wants to schedule a job in the application. In this condition this library internally uses AlarmManager. If Google Play service is available on the device then it uses the scheduling engine inside Google Play services.
这个库也可以在没有安装 Google play 服务,但仍想调度任务的应用上使用。这时,库内部的实现是 AlarmManager。如果设备上有 Google Play 服务,则会使用 Google Play 服务内置的调度器。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个库也可以在没有安装 Google play 服务的设备


### [**Sync Adapter**](https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter.html)

Sync adapters are designed specifically for syncing data between a device and the cloud. It should be only use for this type of task. Syncs could be triggered from data changes in either the cloud or device, or by elapsed time and time of day. The Android system will try to batch outgoing syncs to save battery life and transfers that are unable to run will queue up for transfer at some later time. The system will attempt syncs only when the device is connected to a network.
Sync adapter 是被特别设计用来同步设备和云端数据的。它的用途也只限定在这方面。同步可以在云端或客户端数据有改变时触发,也可以通过时间差或设定每日一次。Android 系统会试图执行批量同步来节省电量,无法同步的将会被放到队列中稍后执行。系统会尝试只在联网时执行同步。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

系统只在联网时会尝试执行同步

@@ -1,90 +1,91 @@
> * 原文地址:[Schedule tasks and jobs intelligently in Android](https://android.jlelse.eu/schedule-tasks-and-jobs-intelligently-in-android-e0b0d9201777)
> * 原文作者:[Ankit Sinhal](https://android.jlelse.eu/@ankit.sinhal)
> * 译文出自:[掘金翻译计划](https://github.com/xitu/gold-miner)
> * 译者:
> * 译者:[PhxNirvana](https://juejin.im/user/57a16f4e6be3ff00650682d8)
> * 校对者:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

校对者:wilsonandusa


Selecting a proper scheduler can improve application performance and battery life of the device.
在近期的应用开发中,异步执行任务是很流行的,而且这些任务经常在应用的生命周期之外运行,如下载上传。有些情况下我们还需要做一些并不是马上需要执行的工作。Android 提供了一些 API 来帮助我们在应用中调度这些任务
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

【下载上传 】 —— 【下载数据或更新网络资源】


When application is running and we want to schedule or run a task at a specific time then it is recommended to use Handler class in conjunction with Timer and Thread. Instead of using Alarm Manger, Job Scheduler etc. it is easier and much more efficient to use [Handler](https://developer.android.com/reference/android/os/Handler.html).
当应用正在运行时,如果我们想在特定时间执行任务的话,推荐使用 Handler 结合 Timer Thread。而不是使用 Alarm Manger, Job Scheduler 等。使用 [Handler](https://developer.android.com/reference/android/os/Handler.html) 更简单高效。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

而不是前面的句号改成逗号吧

Copy link
Contributor

@wilsonandusa wilsonandusa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phxnirvana 校对完毕

@linhe0x0
Copy link
Member

linhe0x0 commented Jul 3, 2017

@ilumer 校对完了吗?

@linhe0x0
Copy link
Member

linhe0x0 commented Jul 3, 2017

@phxnirvana 看起来两个校对者已经校对好了,可以来进行调整了哈。

@phxnirvana
Copy link
Contributor Author

感谢@ilumer @wilsonandusa 两位的校对
@sqrthree 来收热乎稿子~

@phxnirvana phxnirvana closed this Jul 4, 2017
@phxnirvana phxnirvana reopened this Jul 4, 2017
@phxnirvana
Copy link
Contributor Author

Orz。。手滑关了

Copy link
Member

@linhe0x0 linhe0x0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@linhe0x0 linhe0x0 merged commit 5ebeb61 into xitu:master Jul 5, 2017
@ilumer
Copy link

ilumer commented Jul 5, 2017

@sqrthree 桥对完成

@phxnirvana
Copy link
Contributor Author

@phxnirvana phxnirvana deleted the patch-2 branch July 5, 2017 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants