我使用 Evernote 的 Android Job 库。版本 1.2.0。
对于日常工作,我使用 DailyJob ( https://evernote.github.io/android-job/javadoc/com/evernote/android/job/DailyJob.html ),如下所示:
public class DailySyncJob extends DailyJob {
public static final String TAG = "DailySyncJob";
public static void schedule() {
if (!JobManager.instance().getAllJobRequestsForTag(TAG).isEmpty()) {
// job already scheduled, nothing to do
return;
}
JobRequest.Builder builder = new JobRequest.Builder(TAG).setRequiredNetworkType(JobRequest.NetworkType.UNMETERED);
// run job between 11pm and 6am
DailyJob.schedule(builder, TimeUnit.HOURS.toMillis(23), TimeUnit.HOURS.toMillis(6));
}
@NonNull
@Override
protected DailyJobResult onRunDailyJob(Params params) {
// do something
return DailyJobResult.SUCCESS;
}
}
是否onRunDailyJob
启动应用程序类 onCreate()?