JobScheduler多次调用onStartJob(),但作业已完成.一切工作正常,如果我安排一个单一的工作,并等到它完成.但是,如果我同时安排两个或多个具有不同ID的作业,则onStartJob()在调用后再次调用jobFinished().
例如,我使用除ID之外的完全相同的参数来安排作业1和作业2,然后顺序为:
onStartJob() 对于工作1和工作2jobFinished()它们都被调用了onStartJob()对于具有相同ID的两个作业再次调用它我的工作非常基础而且并不复杂.
public class MyJobService extends JobService {
@Override
public boolean onStartJob(final JobParameters params) {
new Thread(new Runnable() {
@Override
public void run() {
try {
// do something
} finally {
// do not reschedule
jobFinished(params, false);
}
}
}).start();
// yes, job running in the background
return true;
}
@Override
public boolean onStopJob(JobParameters params) {
// mark my background task as stopped
// …Run Code Online (Sandbox Code Playgroud) 我正在写一篇关于JobScheduler的教程,我发现了一个奇怪的行为.我要求在1秒内安排3个不同的作业(.setOverrideDeadline(1000)),但它们都被提交并运行了两次......所以这里的代码:
public class MyApplication extends Application {
private static final int JOB_ID_HanlderThread = 100;
private static final int JOB_ID_ExecutorService = 200;
private static final int JOB_ID_AsyncTask = 300;
JobScheduler mJobScheduler;
ExecutorService myExecutorServiceForJobs=null;
private static MyApplication INSTANCE;
public static MyApplication getInstance(){
return INSTANCE;
}
/**
* Called when the application is starting, before any activity, service,
* or receiver objects (excluding content providers) have been created.
* Implementations should be as quick as possible (for example using
* lazy initialization of …Run Code Online (Sandbox Code Playgroud)