Skip to content

Commit

Permalink
添加后台任务停止功能
Browse files Browse the repository at this point in the history
  • Loading branch information
yjfnypeu committed Mar 22, 2018
1 parent 552fee2 commit 42c972b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SampleActivity extends Activity {
@BindView(R.id.has_update_notice) CheckedView hasUpdateNotice; // 选择使用的检测到有更新时的提示
@BindView(R.id.download_complete_notice) CheckedView downloadCompleteNotice; // 选择使用的下载完成后的提示
@BindView(R.id.download_worker) CheckedView downloadWorker; // 选择使用的apk下载网络任务
@BindView(R.id.create_new_config) CheckedView newConfig; // 选择使用的apk下载网络任务
@BindView(R.id.create_new_config) CheckedView newConfig; // 选择使用的apk下载网络任务
boolean isPermissionGrant;// 程序是否被允许持有写入权限
ToastCallback callback;
UpdateBuilder daemonTask;
Expand Down Expand Up @@ -63,6 +63,13 @@ public void call(Boolean aBoolean) {
@OnClick(R.id.start_daemon_update)
void onDaemonStartClick() {
daemonTask = createBuilder();
daemonTask.setUpdateParser(new UpdateParser() {
@Override
public Update parse(String response) throws Exception {
// 设置个无效错误的解析器,使得更新任务失败,以触发后台任务重启逻辑
return null;
}
});
daemonTask.checkWithDaemon(5);// 后台更新时间间隔设置为5秒。
}

Expand All @@ -74,7 +81,7 @@ void onStartClick () {
@OnClick(R.id.stop_daemon_update)
void onStopDaemonClick() {
if (daemonTask != null) {
daemonTask.shutdown();
daemonTask.stopDaemon();
daemonTask = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public boolean isDaemon() {
*
* <p>请注意此方法并不会让当前的更新任务停止,而是停止更新失败后的自动重启功能。</p>
*/
public void shutdown() {
public void stopDaemon() {
if (isDaemon && retryCallback != null) {
retryCallback.detach();
retryCallback = null;
Expand Down

0 comments on commit 42c972b

Please sign in to comment.