-
Notifications
You must be signed in to change notification settings - Fork 76
JobSchedulerCompat could easily drain the battery #15
Comments
Hm, I suspected as much. Can you get any insight into which set of constraints is causing the frequent wakeups? Or, at the very least, could you post what your job setup looks like here? The service should only run just long enough to run the jobs, but if you see it lasing a long time, maybe there is a bug causing it not to be stopped. Also, exactly what error are you getting from |
Hi evant, I will update the job setup later. The error will occur when running sample application on android 2.3 |
Hi @evant, Quite busy with works recently, and here comes my previous job configuration. 1 JobService-------> /**
* When the app's MainActivity is created, it starts this service. This is so that the activity
* and this service can communicate back and forth. See "setUiCalback()"
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_NOT_STICKY;
}
@Override
public boolean onStartJob(JobParameters params) {
// each one will start a intent service with some network background job
switch (params.getJobId()) {
case FEEDSYNC:
JobService.add(new FeedUpdateJob());
break;
case OFFLINESORT:
JobService.add(new OfflineSortNeoJob());
break;
case APPUPLOAD:
JobService.add(new AppUploadNeoJob());
break;
case ONLINESORT:
JobService.add(new OnlineSortNeoJob(true));
break;
}
return true;
} ------< 2 Schedule jobs -----> private void scheduleJobs(int period) {
JobInfo.Builder builder = new JobInfo.Builder(SchedulerService.FEEDSYNC, mServiceComponent);
builder.setRequiredNetworkType(InsightPreferences.getInstance().isFeedSyncOnlyWifi() ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY)
.setPeriodic(period * 60 * 1000);
jobScheduler.schedule(builder.build());
}
private void scheduleJobs() {
scheduleJobs(15);
JobInfo appUploadJob = new JobInfo.Builder(SchedulerService.APPUPLOAD, mServiceComponent)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
jobScheduler.schedule(appUploadJob);
JobInfo onlineSortJob = new JobInfo.Builder(SchedulerService.ONLINESORT, mServiceComponent)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
jobScheduler.schedule(onlineSortJob);
} ------>
After I switch to syncadapter solution, the battery consuming has significantly dropped. from 40% to less 4% per one night Is there anything wrong with my code? |
Hi evant
Thanks for creating this library and bringing one of the best feature of android L to the real world.
I tried to apply JobSchedulerCompat in one of my project, but I soon give it up. cause it consume the battery with unacceptable speed (40% for one night)
I simplely create 3 jobs, each jobs will run a intentservice, there is only one periodic job, and all 3 jobs require network connection.
I check a little bit and turns out that jobscheduler will frequently wake the phone,and last for quite long time. This is a energy killer, I think without resolving this problem, this library could not used in real project ( I know you pointed this out in readme, but I do wish it could be better)
And another issue I try to arise is the sample application could not running correctly (at least) on android 2.3 because of android:permission="android.permission.BIND_JOB_SERVICE" , I don't know if I use this correctly, but not works here~~
The text was updated successfully, but these errors were encountered: