Last active
June 26, 2017 08:35
-
-
Save cwdoh/c7df6f1e064293d988f8d521c796a22c to your computer and use it in GitHub Desktop.
Scaffolding JobService
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.jobscheduler.service; | |
import android.app.job.JobParameters; | |
import android.app.job.JobService; | |
import android.content.Intent; | |
public class SyncJobService extends JobService { | |
ArtworkDownloader mDownloader; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
mDownloader = ArtworkDownloader.getSequencialDownloader(); | |
} | |
@Override | |
public boolean onStartJob(final JobParameters params) { | |
// 신규 Job 수행 조건이 만족되었을 때 호출됩니다. | |
// onStartJob()의 종료 후에도 지속할 동작이 있다면 true, 여기에서 완료되면 false를 반환합니다. | |
// true를 반환할 경우 finishJob()의 호출을 통해 작업 종료를 선언하거나, | |
// 시스템이 필요 onStopJob()를 호출하여 작업을 중지할 수 있습니다. | |
return mDownloader.hasPendingArtworkDownload(); | |
} | |
@Override | |
public boolean onStopJob(JobParameters params) { | |
// 시스템에서 Job 종료 시 호출되며, 현재 처리 중인 동작들을 중지해야 합니다. | |
// 갑작스러운 중지로 현재 실행하던 Job을 재실행해야 할 경우 true, 새로 스케쥴링을 할 필요가 없다면 false를 반환합니다. | |
return !mDownloader.isFinished(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment