1. 使用闹钟服务,让CPU间断式的工作
2. 使用jobScheduler。
JobScheduler的大致流程
1.通过IPC通信执行JobSchedulerStub中的schedule()
2.执行startTrackingJob(jobStatus)。这里会完成job的添加
StateController controller = mControllers.get(i);会在构造方法中初始化
controller.maybeStartTrackingJob(jobStatus);
mTrackedJobs.add(jobStatus);
3.ConnectivityController构造方法,创建了一个广播,在onRevice中进行 updateTrackedJobs(int userId)开始回调StateChangedListener.onControllerStateChanged();
4.在JobSchedulerService实现的onControllerStateChanged方法中发送一个消息
开始把满足执行条件的job找出来maybeQueueReadyJobsForExecutionLockedH
5.通过maybeRunPendingJobsH()方法中vailableContext.executeRunnableJob(nextPending)执行任务
6.new Intent().setComponent(job.getServiceComponent());绑定我们自己写的jobservice进行执行